curl sent Firebase Cloud Messaging alert not visibly appearing on iOS device
P

1

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!!!

Pannier answered 28/6, 2016 at 1:46 Comment(0)
T
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.

Tanganyika answered 28/6, 2016 at 18:13 Comment(3)
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.Wilhelmina
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.Runck
Ok, found my answer for silent notifications on iOS here just FYI: #37570700Runck

© 2022 - 2024 — McMap. All rights reserved.