I am currently trying to implement Firebase Cloud Messaging by following the official Firebase documents.
I have settled the certificates and the provisioning profiles with Push Notifications enabled. I have also installed all the necessary frameworks(FirebaseMessaging,Firebase) using CocoaPods and they seem to work fine.
At the app delegate, I tried to initialize the Firebase cloud messaging token with the code below.
let token = FIRInstanceID.instanceID().token()!
I have also set GCM to enabled and there is a GCM sender id value in the GoogleService-Info.plist.
The error that I am getting is as follows:
2016-11-29 16:11:12.358 Firebasesample[3852:122151] Firebase automatic screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO in the Info.plist
2016-11-29 16:11:12.419: Firebase messaging not setup correctly, nil senderID. fatal error: unexpectedly found nil while unwrapping an Optional value
Thank you in advance for any advice/help.
Was already answered in the comment without the implementation:
Make sure you follow the setup guide on https://firebase.google.com/docs/cloud-messaging/ios/client .
In your didFinishLaunchingWithOptions
add the following method (after FIRApp.configure()
).
NotificationCenter.default.addObserver(self, selector: #selector(tokenRefreshNotification(_:)), name: NSNotification.Name.firInstanceIDTokenRefresh, object: nil)
When your token is refreshed, it will call:
func tokenRefreshNotification(_ notification: Notification) {
guard let token = FIRInstanceID.instanceID().token() else {
QL3("No firebase token, aborting registering device")
return nil
}
//register your token somewhere..
registerToken(token)
}
For those who still having problems on get the token, maybe is because the token has not yet been generated.
On the guide( https://firebase.google.com/docs/cloud-messaging/ios/client ) you can find this part:
When you need the current token, retrieve it. This may return null if the token has not yet been generated.
I hope it helps.
I was stuck with this issue, was not receiving firebase push notification on the IOS device ABOVE IOS-10 because firebase token might be longer than the data type you chose it to be stored with. Check your datatype for the token column. I Have converted from varchar to text and it works and saved our day.
Regards, Gurminder
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.