I updated my pods today to the new Firebase 4.0. I went through the suggested changes and grabbed code from the Github example. I will be honest I am at a loss, I take the F
Firebase Cloud Messaging is quite complex to get set up correctly on iOS, because you have to ensure that your APNs configuration is working, and then add FCM on top of that.
APNs Authentication Keys are also really nice by apple because they don't expire, works in both sandbox and production environments, and the same key (as a .p8
file) can be used to send push notifications to all apps under that Apple Developer account.
It also introduces a new area for a potential failure: typos. You can type in a random bundle id, and as long as the right "team" is configured in Xcode, your app will happily get an APNs device token.
Sending a notification to that device token via APNs (I used this script to send test notifications over HTTP/2 + Auth Keys) will yield a DeviceTokenNotForTopic
error, so that should help you figure out what went wrong.
Checklist
aps-environment
key set to development
(this is automatically updated for you in release builds, by Xcode)application:didRegisterForRemoteNotificationsWithDeviceToken:
. That at least confirms that your APNs set up is okay (but still you might have a typo)Be sure that the GoogleService-Info.plist
file you're using is for the same app as the BUNDLE_ID
key in the plist. I've seen developers think that because APNs Keys should work just fine across all of their apps, that the same GoogleService-Info.plist
is fine across apps, but that's not the case.
Testing
I'd also recommend sending yourself test notifications using FCM's HTTP API from Terminal, to help debug the issue. Unlike the Firebase Notifications Console, it will give you any raw errors it encounters. Here's an example:
curl -X "POST" "https://fcm.googleapis.com/fcm/send" \
-H "Authorization: key=SERVER_KEY" \
-H "Content-Type: application/json" \
-d $'{
"notification": {
"body": "Testing with direct FCM API",
"title": "Test Message",
"badge": "0",
"sound": "default"
},
"registration_ids": [
"FCM_TOKEN"
]
}'
Fill in your SERVER_KEY
with the value in your Firebase Console > Project Settings > Cloud Messaging > Server Key. Replace FCM_TOKEN
with your FCM token.
I use Paw to send test notifications to my apps when I'm working on the FCM SDK.
I was using .p8 file for sending notification, though notification wasn't coming; then I realised the Apple Push Notifications service (APNs) wasn't enabled under .p8 file.
After enabling it, all seems to work now.