Firebase push notifications not working for production on iOS

12,016

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.

Correct certificate to export

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:

  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
Share:
12,016
User123335511231
Author by

User123335511231

Updated on June 09, 2022

Comments

  • User123335511231
    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
    Martijn over 7 years
    This. This was the end of a two week search :)
  • yong ho
    yong ho over 7 years
    This was the end of one day search :)
  • Flavio Kruger
    Flavio Kruger over 7 years
    What do you mean about select the actual certificate, not the private key? Thanks in advance
  • Tope
    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
    deadlock about 7 years
    You've got to be kidding me, once again stackoverflow comes to the rescue. P.S. Firebase still hasn't changed the docs.
  • Chet
    Chet almost 7 years
    Yes, thank you! They click in the wrong place in this article!
  • Harkirat Saluja
    Harkirat Saluja over 6 years
    I only added APN key for development environment and forgot for production. Much thanks for the answer :D
  • Catalin
    Catalin about 6 years
    the newer versions require this: [[FIRMessaging messaging] setAPNSToken:deviceToken type:FIRMessagingAPNSTokenTypeProd];