mori mori - 4 months ago 35
iOS Question

Cannot receive notification in iOS [Firebase]

I'm using Firebase Cloud Messaging and create a cron for my notification instead of using the Firebase console. I'm wondering if I can use the same json i used for android. Currently my android device receives the notification I send but in my iOS it doesn't. I'm wondering if its because some of the parameter I used like in

notification
object for example
icon
is only for android platform, does it effect the result?

My post request looks like this

{
"registration_ids" : $ids,
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark"
"icon" : "myicon"
},
"data" : {
"Nick" : "Mario",
"Room" : "PortugalVSDenmark"
}
}


UPDATE

As suggested, I created two different cron for my iOS and Android, in my iOS i just removed the
icon
parameter in the json. But still i cannot received any notification.

Also under
Capabilities Tab -> Push Notifications
, i toggle it
ON
, also in
Background Modes-> Remote notifications
.

Answer

You can use the same json for both android and ios. Firebase Cloud Messaging will use the relevant parameters for each platform

example:

  • icon will be removed from messages targeting iOS since that platform doesn't support changing the icon.

  • sound should be a filename with extension (extension required for ios). Firebase will remove the extension when targeting an android device.

Regarding the messages not being delivered to iOS try to increase the priority parameter.
https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json

When the ios app is in background Firebase uses APNs to deliver the message, and APNs often delay messages that don't have high priority.

If that doesn't work please check your APNs certificate configuration.