13
votes

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?

4
Ye, I encountered the same problem (push notifications delivered with APNS). No, still not working. - Zeb
@CristiCh do you have any update working on that issue? - Astrowie

4 Answers

32
votes

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

}
8
votes

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.

Correct certificate to export

3
votes

For me these steps resolved the same issue on production:

  1. On Apple Developer portal go to Keys - > Add key enter image description here

  2. Download your key, copy Key ID parameter

  3. Open Firebase Console - > Project settings -> Cloud messaging
  4. Upload your .p8 Key which you downloaded (step 2) here: enter image description here
  5. On new window paste Key ID parameter and your App ID prefix as required
0
votes

I got it working by these steps:

  1. Regenerate the profiles from the Apple developer portal
  2. Remove the old ones
  3. Update the new profiles on firebase console
  4. Conform AppDelegate to the UNUserNotificationCenterDelegate protocol
  5. Make sure all the registration to APNS is done correctly (there are plenty of tutorials on how to do this)
  6. Make sure you called configureFirebase at app startup
  7. Send a message from the firebase console

It seems that step 4 does the difference.