我必须 catch 来自 GCM 的通知。 当我的应用程序处于后台模式时,我没有收到任何通知。但是当它在前景时我可以看到它们。
我使用它来测试 GCM 的功能:
curl -X POST -H "Authorization: key= KKKKKKKKKKKK" -H "Content-Type: application/json" -d '{"to":"XXXXXXXXX","data":{"message": "It is special push notification for test!!!"}}' https://gcm-http.googleapis.com/gcm/send
我看到这条消息(如果应用程序处于事件状态)。 但是当我使用它时:
curl -X POST -H "Authorization: key= KKKKKKKKKKK" -H "Content-Type: application/json" -d '{"to":"XXXXXXXX","data":{"message": "It is special push notification for test!!!"},"notification":{"body":"great match!","title":"Portugal vs. Denmark","icon":"myicon"}}' https://gcm-http.googleapis.com/gcm/send
在这种情况下,我没有看到消息。
您知道如何通过 GCM 发送通知,该通知会在应用关闭时显示吗?
附言看起来 GCM 不适用于 APNs。
最佳答案
您需要发送高优先级参数来通知ios设备。
proirity的描述是;
Sets the priority of the message. Valid values are "normal" and "high." On iOS, these correspond to APNs priority 5 and 10.
By default, messages are sent with normal priority. Normal priority optimizes the client app's battery consumption, and should be used unless immediate delivery is required. For messages with normal priority, the app may receive the message with unspecified delay.
When a message is sent with high priority, it is sent immediately, and the app can wake a sleeping device and open a network connection to your server.
但我认为这还不够描述。
我创建了一个 library for Java 及其测试用例在前台、后台或未运行时通知苹果设备。
关于ios - 如何通过 GCM 向 iOS 设备发送推送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32371847/