简体   繁体   English

我应该存储用于发送推送通知的Android设备令牌吗?

[英]Should I store Android device tokens for sending push notifications?

I am working on an app, which requires Android push notifications to be implemented. 我正在开发一个应用,该应用需要实施Android推送通知。

I have decided to use Firebase Cloud Messaging directly; 我决定直接使用Firebase Cloud Messaging; without using any other abstraction such as AWS SNS or Pusher. 而不使用任何其他抽象,例如AWS SNS或Pusher。

I would like to avoid storing and managing device tokens in the backend, by using the following approach. 我想通过使用以下方法来避免在后端存储和管理设备令牌

In the android app. 在android应用中。

  1. When the user logs into the android application, obtain device token but not send it to the server. 当用户登录android应用程序时,获取设备令牌,但不将其发送到服务器。
  2. Subscribe to a topic that is based on a agreed convention, such that the topic is unique to that user. 订阅基于约定约定的主题,以便该主题对该用户是唯一的。
  3. On logout unsubscribe from the topic. 注销后,退订该主题。

In the Server. 在服务器中。

  1. Whenever a situation arises to send a notification to particular user, send push notification to the topic, that is based on the convention. 每当出现向特定用户发送通知的情况时,都将根据约定将推送通知发送给主题。

I would like to know if this is a viable strategy to avoid managing device tokens ? 我想知道这是否是避免管理设备令牌的可行策略?

Case against using topics. 反对使用主题。

From the official docs . 摘自官方文件

Based on the publish/subscribe model, FCM topic messaging allows you to send a message to multiple devices that have opted in to a particular topic. 基于发布/订阅模型,FCM主题消息传递允许您将消息发送到已选择加入特定主题的多个设备。 You compose topic messages as needed, and FCM handles routing and delivering the message reliably to the right devices. 您可以根据需要编写主题消息,然后FCM处理路由并将消息可靠地传递到正确的设备。

For example, users of a local weather forecasting app could opt in to a "severe weather alerts" topic and receive notifications of storms threatening specified areas. 例如,本地天气预报应用程序的用户可以选择“恶劣天气警报”主题,并接收风暴威胁特定区域的通知。 Users of a sports app could subscribe to automatic updates in live game scores for their favorite teams. 体育应用程序的用户可以为自己喜欢的球队订阅实时比赛得分的自动更新。

I see that topics are recommended, when multiple devices are to be notified. 当要通知多个设备时,我看到建议使用主题。 But I have decided to create a topic per user, this would mean most topics would end up getting subscribed by only one device; 但是我决定为每个用户创建一个主题,这意味着大多数主题最终只能由一个设备订阅。 Is this approach ok ? 这种方法行吗?

I see that topics are recommended, when multiple devices are to be notified 当通知多个设备时,我看到建议使用主题

Yes, multiple devices that have something common to listen to, which is the topic. 是的,这是多个需要共同聆听的设备。 Topics are used for messages that could be received by the general clients since it is public -- ie anyone could subscribe and receive messages sent to it. 因为主题是公开的,所以主题用于一般客户可以接收的消息,即,任何人都可以订阅和接收发送给它的消息。

What is advised to use for multiple devices, but for the same user is to use Device Groups (see my answer here for tips on Managing Device Groups ). 建议用于多个设备,但对于同一用户 ,则要使用设备组(有关管理设备组的提示,请参见我的回答)。 However, if you don't mind the " topics being public " part, then your approach should be fine. 但是,如果您不介意“ 主题公开 ”部分,那么您的方法应该很好。

Yes, Here required device tokens if we want to send push notification whoever installed your app. 是的,如果我们想发送推送通知给安装您应用的人,则此处需要设备令牌。 My research we can save device tokens in back end at first time installation of your app that is better according to my understanding so that we can easy to send push notification across all devices. 根据我的研究,根据我的理解,我们可以在首次安装您的应用程序时将设备令牌保存在后端,这样可以更好地在所有设备之间发送推送通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM