12

I am trying to get Firebase Cloud Messaging iOS alerts sent from my server to FCM to appear on my iOS device.

If I send the message from the FCM console:

https://console.firebase.google.com/project/your-awesome-project/notification

and the FCM sample app:

https://github.com/firebase/quickstart-ios

is closed or in the background, the alerts show up beautifully,

and if it's in the foreground I see this in the iOS console:

{
    aps =     {
        alert = "HEY YO";
    };
    "gcm.message_id" = "0:123456789_blah_blah";
    "gcm.n.e" = 1;
    "google.c.a.c_id" = 123XXXXXXXX789;
    "google.c.a.e" = 1;
    "google.c.a.ts" = 123XXX789;
    "google.c.a.udt" = 0;
}

...but if I try this:

curl -X POST 
--header "Authorization: key=<server key>" 
--header "Content-Type: application/json" 
https://fcm.googleapis.com/fcm/send
-d "{\"to\":\"<device registration id>\",\"notification\":{\"body\": \"HEY YO\"}}"

...it never shows up as an alert, no matter if the FCM sample app is in the foreground, background, or completely closed.

It does however show up in the iOS console but with fewer parameters:

{
    aps =     {
        alert = "HEY YO";
    };
    "gcm.message_id" = "0:123456789_blah_blah";
}

Is it possible to use curl to fire off Firebase Cloud Messaging notifications that appear as alerts on my iOS device?

ANSWER [thanx 2 Arthur!]:

Just add: \"priority\":\"high\"

Like so:

curl -X POST 
--header "Authorization: key=<server key>" 
--header "Content-Type: application/json" 
https://fcm.googleapis.com/fcm/send
-d "{\"to\":\"<device registration id>\",\"priority\":\"high\",\"notification\":{\"body\": \"HEY YO\"}}"

...and I see a beautiful alert notification!!!

ox.
  • 3,579
  • 1
  • 21
  • 21

1 Answers1

12

Yes! It might be that the message you are sending is not being relayed to the device by APNs. Adding the priority field and setting it to high in your curl data should help in this case.

Note however that using high priority is only recommended for release builds when immediate user interaction is expected, like with a chat message.

Arthur Thompson
  • 9,087
  • 4
  • 29
  • 33
  • Thanks, this was frustrating. I tried to explicitly set priority to "normal" and it didn't work either. It might be that I'm using a development APNS cert and this might not be an issue in production. – Chad Pavliska Aug 26 '16 at 02:47
  • Yes, thank you! this was a huge help. Do you know if there is any way to still send these messages with only "data" and NOT the "notification" in the Json? I want to just trigger something in the background, and NOT see the notification. If the app is closed I still see the body that's in the notification. – Eradicatore Jul 30 '19 at 16:23
  • Ok, found my answer for silent notifications on iOS here just FYI: https://stackoverflow.com/questions/37570200/firebase-silent-apns-notification – Eradicatore Jul 30 '19 at 19:43