Google Cloud Messaging showing success message but not sending iOS

别来无恙 提交于 2019-12-05 18:15:28

问题


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!


回答1:


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




回答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.



来源:https://stackoverflow.com/questions/32690850/google-cloud-messaging-showing-success-message-but-not-sending-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!