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!!!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With