【问题标题】:GCM Push Notification not working on iOSGCM 推送通知在 iOS 上不起作用
【发布时间】:2016-02-12 05:40:44
【问题描述】:

我正在尝试将推送消息从服务器发送到我的 iOS 设备。

当我发送以下 JSON 消息时,应用程序正在接收消息(仅在前台) -

{
  "to": "<my_reg_id>",
  "data": 
    {
      "body": "Hello world",
      "title": "Title"
    }
}

但是,当我以Setting up a GCM Client App on iOS(如下所示)给出的格式发送消息时,我在服务器响应中收到"error": "InternalServerError" -

{
  "to": "<my_reg_id>",
  "content_available": true,
  "priority": "high",
  "notification":
    {
      "body": "Hello world",
      "title": "Title"
    }
}

谁能告诉我该怎么办?我真的需要为我的应用接收后台通知。

(附注 - 我在 xCode 中为我的应用启用了远程通知和推送通知功能。)

【问题讨论】:

标签: ios xcode google-cloud-messaging


【解决方案1】:

“内部服务器错误”是服务器端问题。请重新启动服务器并重试。

你的json格式正确

{
  "content_available":true,
  "to":"gcm_registration_token",
  "priority":"high",
  "notification":
    {
    "body":"anything",
    "title":"any title"
    }
}

【讨论】:

  • 没有服务器。我正在使用 Postman 向设备发送消息。这是使用“aps”的问题,也许是我用于 GCM 的证书的问题。
【解决方案2】:

所以我在 JSON 有效负载中使用了“aps”字段,并在 Google Developers Console 上更新了我的证书.....瞧! 我现在在我的设备上接收推送通知。 :D 谢谢大家的帮助:)

【讨论】:

    【解决方案3】:

    从您的 json 中删除 true,@"content_available"。这对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多