0

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.

natsumiyu
  • 3,217
  • 7
  • 30
  • 54
  • The structure for an iOS notification data is different. So, this won't work for iOS. You need to create two different cron jobs, one for iOS and other for Android. – Prerak Sola Jun 02 '16 at 09:11
  • @PrerakSola can I have a sample structure for it? – natsumiyu Jun 03 '16 at 02:53
  • Refer this: https://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH107-SW1 – Prerak Sola Jun 03 '16 at 07:41
  • @PrerakSola instead of using `notification` and `data` object should i change it into `aps`? – natsumiyu Jun 03 '16 at 08:53
  • The priority is needed for iOS if the app is in background: http://stackoverflow.com/questions/37830621/firebase-ios-push-notification-doest-not-work-when-app-is-closed/38093488#38093488 – DiAvisoo Jun 29 '16 at 07:54
  • For push to work on iOS, you must set priority to high. Reference: http://stackoverflow.com/questions/37332415/cant-send-push-notifications-using-the-server-api – Big Pumpkin Jul 28 '16 at 00:33

3 Answers3

2

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

Community
  • 1
  • 1
Big Pumpkin
  • 3,907
  • 1
  • 27
  • 18
1

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.

Diego Giorgini
  • 12,489
  • 1
  • 47
  • 50
0

In my json I added aps object

'aps' => array(
                'alert' => $messageText,
                'badge' => $badge,
                'sound' => 'default',
                'id' => $id
            ),
natsumiyu
  • 3,217
  • 7
  • 30
  • 54