Firebase push notifications not working for production on iOS
Solution 1
First of all check certificate which you are exporting. Typical mistake is to export private key and not a service. I attached a screenshot. I hope that will save some time for you.
Solution 2
I had the same issue. Apparently there is an error in the Firebase documentation. When you exporting the APN certificate for production from your keychain to the .p12 file you have to select the actual certificate, not the private key.
Make sure you upload to the Firebase console this .p12 file in the Cloud Messaging APN certificate settings.
Swift 4.0
Also make sure you're using:
Messaging.messaging().setAPNSToken(deviceToken as Data, type: .prod)
inside:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
#if DEVELOPMENT
//Develop
Messaging.messaging().setAPNSToken(deviceToken as Data, type: .sandbox)
#else
//Production
Messaging.messaging().setAPNSToken(deviceToken as Data, type: .prod)
#endif
}
Solution 3
For me these steps resolved the same issue on production:
Download your key, copy Key ID parameter
- Open Firebase Console - > Project settings -> Cloud messaging
- Upload your .p8 Key which you downloaded (step 2) here:
- On new window paste Key ID parameter and your App ID prefix as required
User123335511231
Updated on June 09, 2022Comments
-
User123335511231 about 2 years
I integrated Firebase Messaging SDK into my iOS project, created a push notification certificate for development and one for production, uploaded both p12 keys to Firebase and I do not receive the notifications, but just for development.
The code for registration is good, and it is the same I used for usual APNS, which worked fine.
The same behaviour happens for 3 applications.
Did someone else encounter this problem? Do you have any solutions or suggestions?
-
Martijn over 7 yearsThis. This was the end of a two week search :)
-
yong ho over 7 yearsThis was the end of one day search :)
-
Flavio Kruger over 7 yearsWhat do you mean about select the actual certificate, not the private key? Thanks in advance
-
Tope about 7 years@FlavioKrugerBittencourt I think this refers to the screen in KeyChainAccess program on OSX. When you select the certificate you have the option to drill down into details and see a key as a sub-item of the certificate. Instead of exporting the key, export the top-level certificate.
-
deadlock about 7 yearsYou've got to be kidding me, once again stackoverflow comes to the rescue. P.S. Firebase still hasn't changed the docs.
-
Chet almost 7 yearsYes, thank you! They click in the wrong place in this article!
-
Harkirat Saluja over 6 yearsI only added APN key for development environment and forgot for production. Much thanks for the answer :D
-
Catalin about 6 yearsthe newer versions require this: [[FIRMessaging messaging] setAPNSToken:deviceToken type:FIRMessagingAPNSTokenTypeProd];