gpt4 book ai didi

ios - iOS 中的 GCM(Google Cloud Messaging)(通知和数据负载。)

转载 作者:行者123 更新时间:2023-11-28 21:32:06 25 4
gpt4 key购买 nike

我有一个问题。对于 iOS,我们可以在有效载荷中同时发送“数据”和“通知”吗?当只有“通知”被发送到 GCM 时,我收到了通知。当我同时添加这两个时,我没有收到任何通知。我的问题是,如果我想在 iOS 和 Android 设备上都获得更新,有效负载应该是什么?

当前负载:

    {
"to":"/topics/testTopic",
"content_available":true,
"priority":"high",
"notification": {
"body":"Test Message",
"title":"test"
},
"data": {
"title": "Title.D Mixed JSON",
"body": "Content.D Mixed JSON",
"productId" : "1"
}
}

最佳答案

您的负载很好,您没有理由不获取它。但这两者之间存在一些差异。"notification""data" 之间的区别记录在官方文档中:https://developers.google.com/cloud-messaging/concept-options

Use notifications when you want GCM to handle displaying a notification on your client app’s behalf. Use data messages when you want your app to handle the display or process the messages on your Android client app, or if you want to send messages to iOS devices when there is a direct GCM connection

因此,对于您要发送的混合消息,了解您的应用程序是在后台还是在前台很重要:

When in the background, apps receive the notification payload in the notification tray, and only handle the data payload when the user taps on the notification. When in the foreground, your app receives a bundle with both payloads available.

收不到推送通知的另一个原因是您没有分配传递优先级。有两个选项normalhigh

High priority. GCM attempts to deliver high priority messages immediately, allowing the GCM service to wake a sleeping device when possible and open a network connection to your app server

正常

Normal priority. This is the default priority for message delivery. Normal priority messages won't open network connections on a sleeping device, and their delivery may be delayed to conserve battery

尝试在有效负载中的 "notification" 之前设置 "priority": "high"

关于ios - iOS 中的 GCM(Google Cloud Messaging)(通知和数据负载。),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35546358/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com