问题描述
我的应用程序正在接收来自2 firebase项目的推送通知.我通过分别调用"getToken(String AuthorizedEntity,String scope)"来获取每个发件人ID的令牌.
My application is receiving the push notification from 2 firebase project. I am getting the tokens for each sender id by calling "getToken(String authorizedEntity, String scope)" separately.
String token1 = FirebaseInstanceId.getInstance().getToken("authorizedEntity1", "FCM");
String token2 = FirebaseInstanceId.getInstance().getToken("authorizedEntity2", "FCM");
根据 onTokenRefresh 文档
应用程序删除实例ID
App deletes Instance ID
应用已在新设备上还原
用户卸载/重新安装应用程序
User uninstalls/reinstall the app
用户清除应用数据
由于 onTokenRefresh 已被弃用,因此我已根据文档检查了 onNewToken .
As onTokenRefresh has been deprecated, I have checked the onNewToken, As per the documentation
第1季度.如何在有多个发件人ID的情况下知道默认的Firebase项目是什么?
Q1. How to know which is the default Firebase project in case of multiple sender id ?
Q2.假设如果将"authorizedEntity1"与默认的firebase项目关联,那么是否意味着仅在token1更改时才会调用onNewToken?还是在令牌2更改时也会调用它?如果不适用于token2,那么如何知道 token2 需要刷新?
Q2. Suppose if "authorizedEntity1" is associated with the default firebase project then does it mean onNewToken will be invoked only when token1 will be changed ? or it will be also invoked when token2 will be changed? If it doesn't work for token2 then how to know that token2 need to be refreshed?
第三季度.参考此我的理解是,每当需要刷新任何令牌时,onTokenRefresh都会被调用(不仅适用于默认项目).这种理解正确吗?
Q3. With reference of this my understanding is onTokenRefresh will be invoked whenever any of the token needs to be refreshed(not only for default project). Is this understanding correct ?
每当系统确定需要刷新 token1 或 token2 时,我都希望将更新的令牌发送到服务器.
I want to send the updated token to the server whenever system determines that the token1 or token2 need to be refreshed.
注意:我正在处理多个发件人ID时,正在我的应用程序类中初始化firebase.
Note: I am initializing the firebase in my application class as I am dealing with multiple sender ids.
推荐答案
经过测试,我发现只有默认项目的令牌将被传递给onNewToken.通过调用getToken为其他发件人ID创建新令牌时,不会调用onNewToken.
After some test, I found out that only default project's token will be delivered to onNewToken. onNewToken will not be called when new token created for other sender ids by calling getToken.
通过调用getToken API检索的令牌由与默认令牌不同的字符串数据组成.
Tokens retrieved by calling getToken API are consist of different string data than default token.
当默认令牌更改时,不会刷新这些其他发件人ID的令牌.直到您显式调用deleteToken API为止,它们似乎一直持续到最后.(当我反复调用getToken时,令牌值没有改变.)
And these other sender id's tokens are not refreshed when default token changes.It look like they last until you explicitly call deleteToken API.(Token value didn't changed when I repeatedly call getToken.)
这篇关于如果有多个发件人ID,如何确定令牌是否需要刷新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!