Google Cloud Messaging showing success message but not sending iOS

前端 未结 2 1386
醉话见心
醉话见心 2021-02-20 16:06

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 g

相关标签:
2条回答
  • 2021-02-20 16:17

    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

    0 讨论(0)
  • 2021-02-20 16:33

    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.

    0 讨论(0)
提交回复
热议问题