gpt4 book ai didi

android - 多个sender id的情况下如何判断token是否需要刷新?

转载 作者:太空狗 更新时间:2023-10-29 13:46:47 25 4
gpt4 key购买 nike

我的应用程序正在接收来自 2 个 firebase 项目的推送通知。我通过分别调用“getToken(String authorizedEntity, String scope)”获取每个发件人 ID 的 token 。

String token1 = FirebaseInstanceId.getInstance().getToken("authorizedEntity1", "FCM");
String token2 = FirebaseInstanceId.getInstance().getToken("authorizedEntity2", "FCM");

根据onTokenRefresh 文档

Called when the system determines that the tokens need to be refreshed. The application should call getToken() and send the tokens to all application servers.This will not be called very frequently, it is needed for key rotation and to handle Instance ID changes due to:

App deletes Instance ID

App is restored on a new device

User uninstalls/reinstall the app

User clears app data

由于 onTokenRefresh 已被弃用,我根据文档检查了 onNewToken

Called when a new token for the default Firebase project is generated. This is invoked after app install when a token is first generated, and again if the token changes.

Q1.如果有多个发件人 ID,如何知道哪个是默认的 Firebase 项目?

问题 2. 假设如果“authorizedEntity1”与默认的 firebase 项目相关联,那么这是否意味着仅当 token1 更改时才会调用 onNewToken?还是在更改 token2 时也会调用它?如果它不适用于 token2 那么如何知道 token2 需要刷新?

Q3.引用this我的理解是只要需要刷新任何 token (不仅适用于默认项目),就会调用 onTokenRefresh。这种理解是否正确?

每当系统确定 token1token2 需要刷新时,我想将更新后的 token 发送到服务器。

注意:我正在我的应用程序类中初始化 firebase,因为我正在处理多个发件人 ID。

最佳答案

经过一些测试,我发现只有默认项目的 token 才会传递给 onNewToken。当通过调用 getToken 为其他发件人 ID 创建新 token 时,不会调用 onNewToken。

通过调用 getToken API 检索的 token 由与默认 token 不同的字符串数据组成。

当默认 token 更改时,这些其他发件人 ID 的 token 不会刷新。看起来它们会持续到您明确调用 deleteToken API 为止。(我反复调用getToken时,Token值没有改变。)

关于android - 多个sender id的情况下如何判断token是否需要刷新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52328630/

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