- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在使用 swift 和 firebase。以前我使用以下方法获取 firebase token ,然后我用它存储到数据库中以发送通知。
InstanceID.instanceID().token()
自从我更新了我的 firebase 后,此方法显示为已弃用。
'token()' is deprecated: Use instanceIDWithHandler: instead.
我不知道如何使用 instanceIDWithHandler
我尝试了以下但不知道如何获取 token 。
func instanceID(handler: @escaping InstanceIDResultHandler){
}
请帮忙。提前谢谢你。
最佳答案
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.
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.
您应该导入 FirebaseInstanceID
import FirebaseInstanceID
objective-c
在你的 getTokenMethod 上
[[FIRInstanceID instanceID] instanceIDWithHandler:^(FIRInstanceIDResult * _Nullable result,
NSError * _Nullable error) {
if (error != nil) {
NSLog(@"Error fetching remote instance ID: %@", error);
} else {
NSLog(@"Remote instance ID token: %@", result.token);
}
}];
swift
InstanceID.instanceID().instanceID { result, error in
if let error = error {
print("Error fetching remote instange ID: \(error)")
} else if let result = result {
print("Remote instance ID token: \(result.token)")
}
}
更新
InstanceID
现已弃用。尝试
Messaging.messaging().token { token, error in
// Check for error. Otherwise do what you will with token here
}
关于swift - Firebase InstanceID.instanceID().token() 方法已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50945015/
我是一名优秀的程序员,十分优秀!