我是 firebase 的新手,我正在学习它,就像一个蹒跚学步的孩子学习走路一样.到目前为止,我已经设法使用 firebase 框架为我的手机生成的令牌向我自己的手机发送消息.现在这是棘手的地方(在我看来).FirebaseInstanceIdService
扩展服务中有一个名为onTokenRefresh()
的方法.既然叫refresh,那么我假设它会改变.我想知道这个令牌是什么时候创建的,什么时候会改变?
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?
token 生成,app 首次启动后,只要手机能连接到谷歌服务器.由于所需的连接性,这可能不会立即发生,但在大多数情况下,它会在用户打开应用程序后几秒钟内发生.一旦生成令牌,就会调用方法 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的app token在什么时期发生变化,如何管理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!