gpt4 book ai didi

android - 发布/订阅 FCM 主题

转载 作者:行者123 更新时间:2023-11-30 00:49:42 25 4
gpt4 key购买 nike

我以前从未使用过 FCM(或 GCM),但我正在研究编写一个涉及向多个设备发布消息的应用程序,而“主题”似乎是一个不错的方法。

根据我目前阅读的文档,我的应用程序服务器会将消息发布到指定主题,因此大概它不需要了解接收方设备的注册 token ?

我认为订阅主题时必须指定注册 token ,所以我猜接收方设备在订阅之前仍必须请求 token 。 token 过期时会发生什么 - 应用是否必须使用新 token 再次订阅主题?

最佳答案

so presumably it doesn't need to know about registration tokens for the recipient devices?

没有。它没有。但我强烈建议您保存注册 token ,以便您可以使用 Diagnostics tool 跟踪它们。 future 。

What happens when the token expires - does the app have to subscribe to the topic again, using the new token?

在 Android 中,您只需调用

FirebaseMessaging.getInstance().subscribeToTopic(<topic_name_here>);

为设备订阅一个主题。解释了我如何理解这项工作的方式 here ,其中 FirebaseMessaging 类调用 FirebaseInstanceId 的实例并(大概)订阅当前 Activity 的注册 token 。

根据 @DiegoGiorgini's answer here ,如果 token 被刷新,主题订阅将被维护。

据我所知(还没遇到),应该重新订阅相应的注册 token 。取决于您实现订阅的位置。

我建议在应用程序本身启动时使用它。如果你的 App Server 上有一个主题列表(如果有多个),并且可能使用 InstanceID API 会更好。如果需要重新订阅。

关于android - 发布/订阅 FCM 主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41267356/

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