I'm trying to add push notifications to my Ionic app using FCM and running into issues with IOS, (android works as intended). Before marking this as a duplicate, Ive tried the solutions from the other similar questions but it didnt help.
In the firebase console I have set the team Id, App id as well as uploded the APNS p5 generated by apple to my console as well.
And finally, the latest plist file to my app's root. From xcode, I can see the certificate has push notifications enabled too and the app asks for that permission for it as well. After that I got the device notification id and tested it via the console as well as the api endpoint but I keep getting the "InvalidApnsCredential" error. I did the steps from few other questions from here but had no luck. I cant seem to get it working, below is a few snippets of my code
this.platform.ready().then(() => {
this.fcmService.getToken().then(resp=>{
this.httpService.sendToken(resp)
.subscribe(res => {
console.log(res)
});
console.log(resp)
});
});
And the body of the api post request
Endpoint: https://fcm.googleapis.com/fcm/send
Body:
{
"notification":{
"title":"Ionic 4 Notification",
"body":"This notification sent from POSTMAN using Firebase HTTP protocol",
"sound":"default",
"click_action":"FCM_PLUGIN_ACTIVITY",
"icon":"fcm_push_icon"
},
"data":{
"landing_page":"second",
"price":"$3,000.00"
},
"to":"IOS_DEVICE_NOTIFICATION_ID",
"priority":"high",
"restricted_package_name":""
}
The code and api endpoint seems correct as it works for Android. Is there anything im missing to get it working?
So, this may not be exactly the answer that youre looking for but, for me everything worked fine after i recreated the app on ios. Common issues include - trying to send a notification before the client gives premission - sending notifications using older IDs (yes they change sometimes) - package name mismatch between your app and ios app
Following are the reasons of "InvalidApnsCredential":
In my case, I forgot to enter and upload the APNs Authentication Key
in the firebase console. Please go to the
- Cloud Messaging -> Apple app configuration
Add AuthKey File(.p8), Key Id & Team ID
Check the image below. And it's working fine for me.
Make sure Team ID
is added in the SDK setup and configuration.
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.