gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 03:52:47 24 4
gpt4 key购买 nike

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

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

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

  • 主题消息传递 (messaging().sendToTopic):我的理解是,这是为了向更大的组发送相同的通知。例如,一个主题可以是所有想要纽约天气通知的用户。不适用于我的用例。

  • Send Multicast (messaging().sendMulticast([array of tokens]):据我所知,这会将相同的消息发送到数组中的所有设备 token (最多 100 个)。这似乎很适合我的用例,对吧?

  • Device group messaging (messaging().sendToDeviceGroup):这个我不太懂。为什么要使用它而不是多播或主题?

对于我的用例,最好的方法似乎是每次更新 FCM token 时,我将此 token 添加到数据库中的用户。然后我使用 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.

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

关于firebase - FCM 向多个设备发送消息 - 使用哪种方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62047121/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com