Google Cloud Messaging 显示成功消息但未发送 iOS [英] Google Cloud Messaging showing success message but not sending iOS

查看:23
本文介绍了Google Cloud Messaging 显示成功消息但未发送 iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我遇到了 Google Cloud Messaging 一个非常奇怪的问题.我遇到的问题是它成功注册了设备,当发送消息时,我收到了来自 Google 的成功消息.但设备从未收到任何消息.

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.

我从 GCM 得到的消息是:

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\"}]}"

为了让事情变得更加混乱,我的实现大约在 2 周前开始工作,迄今为止我没有更改任何内容.该应用的 Android 版本接收消息没有问题,只是 iOS 实现无法正常工作.

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.

任何帮助将不胜感激!

谢谢!

推荐答案

所以我在拔掉头上最后剩下的头发后终于解决了这个问题.

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

事实证明设备正在接收消息,但默认情况下 GCM 将优先级设置为最低优先级.这意味着设备收到通知但从不显示它.此优先级用于静默通知以在后台唤醒应用程序.我发现了这一点,因为我一直在控制台中收到消息说:

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:

低优先级推送:[com.test.app] - 不支持后台刷新

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

优先级是一个介于 1 和 10 之间的值,因此我将优先级设置为 10 并立即在设备上收到消息.我的 GCM POST 请求正文现在看起来像这样:

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.

(ノಠ益ಠ)ノ

您可以将优先级"设置为高",这与将其设置为10"完全相同(优先级是 0 到 10 之间的值.Google 将文本转换为 iOS 的数字

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

这篇关于Google Cloud Messaging 显示成功消息但未发送 iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆