firebase 的应用令牌在什么时间段发生变化以及如何管理它? [英] In what period does the firebase's app token changes and how to manage it?

查看:15
本文介绍了firebase 的应用令牌在什么时间段发生变化以及如何管理它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 firebase 的新手,我像学走路的蹒跚学步的孩子一样学习它.到目前为止,我已经设法使用 firebase 框架为我的手机生成的令牌向我自己的手机发送消息.现在这就是它变得棘手的地方(在我看来).FirebaseInstanceIdService 扩展服务中有一个名为 onTokenRefresh() 的方法.既然它被称为刷新,那么我假设它会改变.我想知道这个token什么时候创建,什么时候改?

I am new to firebase I am learning it like a toddler learning to walk. So far I have managed to send a message to my own phone using a token generated for my phone by firebase framework. Now here's where it gets tricky (in my opinion). There is a method called onTokenRefresh() in the FirebaseInstanceIdService extended service. Since it is called refresh, Then I am assuming that it will change. I want to know when this token is created and when will it be changed?

如果它发生变化,假设我向具有令牌A"的设备发送一条消息,该设备目前处于离线状态,因此它将排队.现在,当设备上线时,它会将令牌刷新"为B".现在,由于消息应该传递给令牌A",因此永远不会传递消息.我该如何处理这种情况?

And if it changes, suppose I send a message to a device with token 'A' which is offline for now, so it will be queued. Now when the device gets online, it will "refresh" the token to 'B'. Now as the message was supposed to be delivered to token 'A', the message will never be delivered. How can I manage this situation?

推荐答案

令牌生成,应用程序首次启动后,手机可以连接到谷歌服务器.由于需要连接,这可能不会立即发生,但在大多数情况下,它会在用户打开应用程序后几秒钟内发生.一旦生成令牌,就会调用方法 onTokenRefresh().

The token is generated, after the app is first launched, as soon as the phone can connect to the Google servers. Due to the required connectivity this might not happen immediately, but in most of the cases it will happen in few seconds after the user open the app. As soon as the token is generated the method onTokenRefresh() is called.

正如您所指出的,令牌可以更改,在这种情况下,将再次调用 onTokenRefresh() 方法.
刷新事件在某种程度上很少见,不要指望经常看到它.

As you pointed out the token can change, in which case the onTokenRefresh() method will be called again.
The refresh event is somehow rare, don't expect to see it often at all.

当刷新令牌发生时,所有已经成功"发送到旧令牌的消息(API 返回给你一个消息 ID)都将被传递.

When the refresh token happens, all the messages that have been "successfully" sent (the API returned you a message-id) to the old token will be delivered.

最后,即使在刷新发生后,旧令牌仍将在短时间内工作,以允许应用将新令牌传达给其后端.

Finally, even after the refresh happened the old token will still be working for a short period, to allow the app to communicate the new token to its back-end.

这篇关于firebase 的应用令牌在什么时间段发生变化以及如何管理它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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