Google Cloud Messaging showing success message but not sending iOS
Asked Answered
H

2

10

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!

Horta answered 21/9, 2015 at 8:45 Comment(1)
Can you paste your full HTTP request header and body? You can also try to set the higher priority for your message, or change the lifespan of your message.Santa
H
13

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

Horta answered 28/9, 2015 at 6:55 Comment(3)
I also had to manually create a provisioning profile (rather than using Xcode's "Automatic" setting) for my app to get GCM to work. I was experiencing the same issue you reported (GCM says it was successful, but the device never received it), except all subsequent attempts to send a push notification after that would fail with "NotRegistered". I think that not having a provisioning profile somehow resulted in GCM thinking the registration token was no longer valid (after the first attempt). Anyway thanks for sparing me most of the hairs on my head!Caracul
you are right . you saved me from pulling my hair ;-). however i was starting to do soPard
If anyone is using FCM, you can use "priority":"high"Sanitarian
P
2

Instead of adding "priority" : 10, You should add the following line: "content_available" : true,

In APNS server (iOS), The content_avaialble changes to 1 which leads the push notification in background. And adding "priority":10, will drain more iphone battery. In my case I don't even have anything related to priority, but it still works.

Prosaism answered 28/1, 2016 at 19:21 Comment(1)
This worked for me, after days of frustration. Thanks!Chemesh

© 2022 - 2024 — McMap. All rights reserved.