Firebase的应用令牌在哪个时间段更改以及如何管理? [英] In what period does the firebase's app token changes and how to manage it?

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

问题描述

我是新来的firebase我正在学习它像一个学步行走的蹒跚学步。到目前为止,我设法使用Firebase框架为我的手机生成的令牌向我自己的手机发送消息。现在这里是棘手的(在我看来)。在 FirebaseInstanceIdService 扩展服务中有一个称为 onTokenRefresh()的方法。因为它被称为刷新,那么我认为它会改变。我想知道什么时候这个令牌被创建,什么时候会被改变?

如果它改变了,假设我发送一条消息给一个带有tokan'A'的设备现在离线了,所以会排队。现在,当该装置上线时,它将刷新该标记为B。现在,由于该消息应该被传递给标记A,所以该消息将永远不会被传递。我怎样才能管理这种情况?

由于所需的连接性,这可能不会立即发生,但在大多数情况下,它会在用户打开应用程序后的几秒钟内发生。
一旦生成了标记,就会调用 onTokenRefresh()这个方法。



出令牌可以改变,在这种情况下, onTokenRefresh()方法将被再次调用。

刷新事件是罕见的,不要期望当刷新令牌发生时,所有已经成功发送的消息(API返回给你一个消息ID)到旧的令牌将被交付。
$ b p

最后,即使在刷新发生之后,旧的令牌仍然会在短时间内运行,以允许应用程序将新的令牌它的后端。

I am new to firebase I am learning it like a toddler learning to walk. So far I 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?

And if it changes, suppose I send a message to a device with tokan 'A' which is offline for now, so it will be queued. Now when the deice 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?

解决方案

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.

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.

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天全站免登陆