当我尝试在XCode中编译我的应用程序时,我会遇到这种情况,在android中它运行得很完美,但在那里,它失败了,这是我直接从Firebase云中使用的函数。
func messaging(_ messaging: Messaging, didReceiveRegistrationToken
fcmToken: String) {
print("Firebase registration token: (fcmToken)")
let dataDict:[String: String] = ["token": fcmToken]
NotificationCenter.default.post(name: Notification.Name("FCMToken"),
object: nil, userInfo: dataDict)
// TODO: If necessary send token to application server.
// Note: This callback is fired at each app startup and whenever a
new
token is generated.
}
这就是我问题标题中提到的错误标记我的地方,如果有人发生在他身上,他可以帮助我,因为我在这里没有看到类似的错误。
除了@Rashid的答案,您还需要更新消息传递函数中的dataDict。
只需添加?? ""
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
print("Firebase registration token: (String(describing: fcmToken))")
let dataDict:[String: String] = ["token": fcmToken ?? ""]
NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
// TODO: If necessary send token to application server.
// Note: This callback is fired at each app startup and whenever a new token is generated.
}
这直接来自文档:https://firebase.google.com/docs/cloud-messaging/ios/client
使用最新的Firebase Messaging(7.0.0(,该函数已更新为具有可选的fcmToken。将其更新为以下内容将有所帮助:
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?)
试试这个:
optional func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {