GCM 推送通知无法在 iOS 上运行

GCM Push Notification not working on iOS

我正在尝试从服务器向我的 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"
    }
}

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

(P.S。-我在 xCode 中为我的应用程序启用了远程通知和推送通知功能。)

"Internal server error" 是服务器端问题。请重新启动服务器并重试。

您的json格式正确

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

所以我在 JSON 有效负载中使用了字段 "aps",并且还在 Google 开发人员控制台上更新了我的证书......瞧! 我现在可以在我的设备上接收推送通知。 :D 感谢大家的帮助:)

从你为我工作的 json.This 中删除 true,@"content_available"