如果有多个发件人ID,如何确定是否需要刷新令牌? [英] How to determine if token needs to be refreshed in case of multiple sender id?

查看:15
本文介绍了如果有多个发件人ID,如何确定是否需要刷新令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序正在接收来自 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 文档

当系统确定令牌需要刷新时调用.应用程序应该调用 getToken() 并将令牌发送到所有应用程序服务器.这不会很频繁地调用,它是密钥轮换和处理实例 ID 更改所必需的,原因如下:

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:

应用删除实例 ID

应用在新设备上恢复

用户卸载/重新安装应用程序

User uninstalls/reinstall the app

用户清除应用数据

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

As onTokenRefresh has been deprecated, I have checked the onNewToken, As per the documentation

在为默认 Firebase 项目生成新令牌时调用.这是在首次生成令牌时在应用安装后调用的,如果令牌更改,则会再次调用.

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 项目?

Q1. How to know which is the default Firebase project in case of multiple sender id ?

Q2.假设如果authorizedEntity1"与默认的firebase项目相关联,那么这是否意味着只有在更改token1时才会调用onNewToken?还是在更改 token2 时也会调用它?如果对 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?

Q3.参考 this 我的理解是,只要需要刷新任何令牌(不仅适用于默认项目),都会调用 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 ?

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

I want to send the updated token to the server whenever system determines that the token1 or token2 need to be refreshed.

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

Note: I am initializing the firebase in my application class as I am dealing with multiple sender ids.

推荐答案

经过一番测试,我发现只有默认项目的token会传递给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 时,Token 值没有变化.)

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,如何确定是否需要刷新令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆