Firebase Cloud Messaging on iOS not working properly
Asked Answered
R

4

5

I added to my project Firebase Cloud Messaging for receiving and sending push notifications. I followed steps in original tutorial from Google. The result was exciting, I can receive push notification on my device - I published it to TestFlight - problem occurred.

I realize that I need to create different certificate. (???) Then I delete my key (.p8) from Firebase Cloud messaging and recreated it (development too) + I recreated same development provisioning profile (old ones I revoke), I repeated process from tutorial but now I can't get push notification even in my device, neither on TestFlight.

Can anyone help me with these questions?

  1. Which certificate/profile I should create? For now, I have created .p8 key for development and provisioning profile for development (not working anymore)
  2. Should I change something in my code? I found somewhere that I should change URL from sandbox to prod, Firebase do it automatically? It's problem in device token? I can't recieve even test notification when I copy / paste FCM token to console.
  3. It's possible to send silent push notification from Firebase Messaging Console? (Can I set all required headers in Firebase console?)
  4. Difference between .p8 and .p12? It's possible to have .p8 key for production?

Please help me from this. Thanks!

[UPDATE][SOLVED] After completing the steps from this answer and changing the Team ID in Firebase to same Team ID from Apple Developer I was able to receive notification to my device and all the TestFlight devices.

Rancho answered 23/3, 2020 at 8:49 Comment(0)
G
10

Firebase has nothing to do with the development and production. It would be on your end if you are using two different firebase apps, one for the development and other for the production.If that is the case you just have change the GoogleService-Info.plist for the respective environments. Here are my steps you should follow to properly implement Firesbase Push Notifications.

1) Go to your apple developer account and create a new key for APNS. (Reference)

2) Create a firebase project and add an iOS app, then in Cloud Messaging tab in the your App settings add the Key you just created in the 1st step with KeyID and TeamID.

3) Add the GoogleService-Info.plist to the root of your project and add the Push Notification from the capabilities in Xcode.

4) Then initialize the firebase in your app (Reference)

5) Add the code to ask for Notification permissions on app startup.

6) And finally get the fcmToken from this method

func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String)

And send a notification to that token from firesbase.

Note: For provisioning profiles, enable the automatic signing in Xcode and Xcode will do the signing process itself. Now we don't need create the provisioning profiles manaually.

Glynn answered 23/3, 2020 at 10:52 Comment(10)
Hi there, I delete all the code connected to Firebase Cloud Messaging, I delete the app from my phone, clear the build in Xcode, delete server in Firebase Cloud Messaging, delete the old key from Firebase and Developer, delete provisioning profile. I follow all the steps what you wrote, I successfully receive fcmToken, copy it and paste it to Firebase test notification - nothing happen.Carib
Make sure your app is not running while sending notification.Glynn
I am sure. Shoud I have MyApp.entitlements file in my project ? I don’t have and I see it somewhere in tutorial.Carib
Yeah i see, github.com/PeHk/AcademicInformationSystem, my project is open-source because is my bachelor thesis. Should the entitlements file look like this? <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>aps-environment</key> <string>development</string> </dict> </plist>Carib
Please double check that your firebase app has the same bundleID as your iOS app and you have added the correct GoogleService-Info.plist.Glynn
Read this article and try the suggested solutions there. firebase.googleblog.com/2017/01/…Glynn
Just to keep you inform that Push Notifications works on real device(not on simulator) till the Xcode11.4. I hope you are testing it on real device.Glynn
Let us continue this discussion in chat.Carib
I've done all these things and followed the chat but nothing works to show up a notification on the deviceNematode
I can understand being close and having a few minor things wrong, and maybe that's my case too, but I'm uncertain about the fcm token originating from the appledelegate file when I already have it generated at Flutter. It's when I call the cloud-function and send the fcm token that things then go not-to-plan. An example with code would've been even better.Asexual
A
1

In our case it was that in the main project settings the team id was set to the team name, after changing that and uploading the APN key again with the right team id it started working, so you might want to double check that.

Armhole answered 3/2, 2021 at 10:33 Comment(0)
S
1

In my case it was the wrong APNs Authentication Key we have uploaded the wrong file to firebase console, once replaced with the correct APN key, the notifications worked like a charm. No changes to the code needed

Septime answered 22/6, 2021 at 16:56 Comment(0)
S
1

Make sure you don't rename the auth key file

In my case, I had renamed the auth key file to something else and that was causing the issue. I tried naming it back to the default format AuthKey_<KeyID>.p8 and everything started working.

Stammel answered 6/1, 2022 at 14:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.