Cannot receive notification in iOS [Firebase]

2019-09-10 11:42发布

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.

3条回答
可以哭但决不认输i
2楼-- · 2019-09-10 12:21

In my json I added aps object

'aps' => array(
                'alert' => $messageText,
                'badge' => $badge,
                'sound' => 'default',
                'id' => $id
            ),
查看更多
仙女界的扛把子
3楼-- · 2019-09-10 12:28

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.

查看更多
Bombasti
4楼-- · 2019-09-10 12:43

For Firebase push to work on iOS, you must set priority to high. Reference: Can't send push notifications using the server API

查看更多
登录 后发表回答