Firebase InstanceID.instanceID().token() method is deprecated(Firebase InstanceID.instanceID().token() 方法已弃用)
问题描述
我正在使用 swift 和 firebase.以前我使用以下方法获取 firebase 令牌,然后我将其存储到数据库中以发送通知.
现在这种方法显示为已弃用,因为我已经更新了我的 firebase.
我不知道如何使用 instanceIDWithHandler
我尝试了以下但不知道如何获取令牌.
请帮忙.提前谢谢你.
获取当前注册令牌
<块引用>注册令牌通过 messaging:didReceiveRegistrationToken:
方法传递.此方法通常在每个应用程序以 FCM 令牌启动时调用一次.调用此方法时,最理想的时机是:
<块引用>
- 如果注册令牌是新的,请将其发送到您的应用服务器.
- 为主题订阅注册令牌.这仅适用于新订阅或用户重新安装应用的情况.
您可以使用 instanceIDWithHandler:
直接检索令牌.此回调提供一个 InstanceIDResult
,其中包含令牌.如果 InstanceID 检索以任何方式失败,则会提供非 null 错误.
您应该导入 FirebaseInstanceID
目标 C
在您的 getTokenMethod 上
斯威夫特
I am working with swift and firebase. Previously I was using following method to get firebase token which then I was using to store into database to send notifications.
Now this method is showing as deprecated since i have updated my firebase.
I don't know how to use instanceIDWithHandler
i have tried following but don't know how to get token.
Please help. Thank you in advance.
Fetching the current registration token
Registration tokens are delivered via the method
messaging:didReceiveRegistrationToken:
. This method is called generally once per app start with an FCM token. When this method is called, it is the ideal time to:
- If the registration token is new, send it to your application server.
- Subscribe the registration token to topics. This is required only for new subscriptions or for situations where the user has re-installed the app.
You can retrieve the token directly using
instanceIDWithHandler:
. This callback provides anInstanceIDResult
, which contains the token. A non null error is provided if the InstanceID retrieval failed in any way.
You should import FirebaseInstanceID
objective C
on your getTokenMethod
Swift
这篇关于Firebase InstanceID.instanceID().token() 方法已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!