问题描述
从何处、何时检索令牌以及何时可用?
From where and when is the token retrieved and when is it available?
它是对 Firebase 服务器的同步调用吗?如果我在应用生命周期中过早调用它,它可能还没有被填充吗?
Is it a synchronous call to the Firebase server? If I call it too soon in the app lifecycle, might it not have been populated yet?
推荐答案
从何时何地检索令牌以及何时可用?
令牌由 FCM Instance ID 服务在后台生成,该服务会在您的应用运行后立即启动.关于如何生成令牌的详细信息尚不清楚,但我认为设备需要与互联网建立良好的连接才能与令牌的 FCM 服务器进行通信.
The token is generated by the FCM Instance ID service in the background, which starts as soon as your app runs. The details on how the token gets generated is unclear, but how I see it is that the device needs a decent connection to the internet in order for it to communicate with the FCM servers for the token.
是对 Firebase 服务器的同步调用吗?
从技术上讲,没有.如 docs 中所述:
Technically speaking, no. As mentioned in the docs:
FirebaseInstanceID.getToken() 如果尚未生成令牌,则返回 null.
FirebaseInstanceID.getToken()returns null if the token has not yet been generated.
此时,如果令牌为空,您应该期望在您的 onNewToken() 中有一个触发器,然后您可以在其中调用 getToken(),它现在应该包含令牌.
At this time, if the token is null, you should expect a trigger in your onNewToken() where you could then call getToken() which should now contain the token.
如果我在应用生命周期中过早调用它,它可能还没有被填充吗?
通常可以尽快调用 getToken() - 在您应用的 MainActivity 中 - 在大多数情况下,当您的应用到达该点时,它已经有了一个值.但是话又说回来,如果它为null,您仍然应该正确处理它.
It's usually okay to call getToken() as soon as possible -- in your app's MainActivity -- in most cases, by the time your app reaches that point, it already has a value. But then again, you should still handle it properly if it is null.
这篇关于FirebaseInstanceId.getInstance().getToken() = null 什么时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)