FCM 向多个设备发送消息 - 使用哪种方式?

FCM Send message to multiple devices - which way to use?

FCM消息的发送方式有很多种,文档看了一遍也不知道该用哪个。

我的用例: 我有一个用户在她的 iPhone、iPad 和 Android 平板电脑上登录了该应用程序。我想确保将推送通知发送到她的所有设备。

可以通过三种方式执行此操作(我正在使用管理员发送推送通知):

对于我的用例,最好的方法似乎是每次更新 FCM 令牌时,我将此令牌添加到数据库中的用户。然后我使用 admin.messaging().sendMulticast([array of tokens]) 发送通知。这是你会推荐的吗?为什么或为什么不?

如果您的目标是单个用户的特定设备,您可能希望使用多播。您可能不想使用设备组。我建议阅读 documentation 以了解设备组的工​​作原理:

Device group messaging allows you to add multiple devices to a single group. This is similar to topic messaging, but includes authentication to ensure that group membership is managed only by your servers. For example, if you want to send different messages to different phone models, your servers can add/remove registrations to the appropriate groups and send the appropriate message to each group. Device group messaging differs from topic messaging in that it involves managing device groups from your servers instead of directly within your application.

设备组基本上只是主题,其成员资格完全由您的服务器代码管理,而不是由客户端代码管理。