ios - 如何通过 GCM 向 iOS 设备发送推送通知?

标签 ios iphone push-notification google-cloud-messaging

我必须 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/

相关文章:

android - FCM 推送通知 : MismatchSenderId

android - PWA 的推送通知或 Web 推送通知

ios - objective-C : Issue faced while editing multiple row simultaneously in table view

iphone - RestKit:如何为不同的键名进行映射

iphone - 适用于 iOS 的高质量文本转语音 SDK

ios - MapView 添加多个不同颜色的注解

android - 向 Android 发送推送通知

android - 是否可以将 firebase 自定义属性分析设置为数组?

ios - 在 UITableViewCell 中使用 UISegmentedControl 传递数据

android - 移动开发的 future