I am trying to send notifications to an IOS device using Firebase Cloud Messaging - every IOS project in the Firebase Console has a valid APNs P8 Auth Key, freshly generated from the Apple developer account for this purpose.
I'm using this approach:
curl -X POST \
https://fcm.googleapis.com/fcm/send \
-H 'Authorization: key=<My Key>' \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{
"to": "<Device Token>",
"notification": {
"title": "Push Notification Test to IOS",
"body":"Push Notification Test to IOS"
},
"data": {
"message": "Push Notification Test to IOS"
}
}'
This results in the following error from FCM:
{
"multicast_id": <Id>,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "InvalidApnsCredential"
}
]
}
If I remove the "notification" block from the message, FCM responds with a success, but nothing is received on the device.
I can send and receive notifications using the above example message to Android devices just fine.
The FCM documentation suggests that when a "notification" block is included, FCM attempts to send via APNs when the token is for an IOS device:
If a notification payload is provided, or the content_available option is set to true for a message to an iOS device, the message is sent through APNs, otherwise it is sent through the FCM connection server.
What I have tried:
I had the same problem and then I create a P8 file and upload it to firebase in your project and start working the notification field
Link in portuguese How to install the P8 file to firebase
InvalidApnsCredential
doesn't means the issue is directly related to the APNS certificate nor the key.
I my case, I faced this problem with a white labeled app & after investigation, I found that my app bundle id (PRODUCT_BUNDLE_IDENTIFIER) was not matching the one in Firebase (I was using a development bundle id instead of the production one).
Make sure that your Bundle ID is correct.
If it's not the same, create a new iOS app ( Configuration → General → Add an app ) and make sure to set the name correctly.
In my case, I had the shortest version of the bundle ID ( com.company
) instead of the long one ( com.company.appname
).
Doing this you should not need to re-compile and re-upload the app.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.