Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Messaging showing success message but not sending iOS

So I have run into a very strange problem with Google Cloud Messaging. The problem I am having is that it is registering the devices successfully, and when a message is sent I get a success message from Google. But the devices never receive any messages.

The message I get back from GCM is:

"result": "Push notification sent successfully: {\"multicast_id\":6008387530769664000,\"success\":1,\"failure\":0,\"canonical_ids\":0,\"results\":[{\"message_id\":\"0:1442824842607522%73fc535e73fc535e\"}]}"

To make things even more confusing, my implementation was working about 2 weeks ago and I have not changed anything to date. The Android version of the app is receiving messages with no problems it is only the iOS implementation that is not working.

Any help would be much appreciated!

Thanks!

like image 710
Nick Kirsten Avatar asked Sep 21 '15 08:09

Nick Kirsten


1 Answers

So I finally solved this issue after of pulling the last remaining hairs out of my head.

It turns out the devices are receiving the messages but GCM sets the priority to the lowest priority by default. This means the device receives the notification but never displays it. This priority is used for silent notifications to wake the app up in the background. I discovered this because I kept receiving the message in the console saying:

Low Priority Push: [com.test.app] - Background Refresh Not Supported

Priority is a value between 1 and 10 so I then set the priority to 10 and got the message instantly on the device. My GCM POST request body now looks like this:

{
  "to": "GCM token here",
  "notification": {
    "sound": "default",
    "badge": "2",
    "title": "default",
    "body": "Test Push!",
  },
   "priority" : 10,
} 

I really hope this helps others as I have spent a week pulling my hair out regarding this.

(ノಠ益ಠ)ノ

EDIT:

You can set "priority" to "high" and that works exactly the same as setting it to "10" (priority is a value between 0 and 10. Google coverts the text to the number for iOS

like image 152
Nick Kirsten Avatar answered Sep 28 '22 08:09

Nick Kirsten