简体   繁体   English

GCM未在通知中使用JSON有效负载中的数据

[英]GCM not using data from JSON payload in the notification

I am sending the following JSON through GCM (Google Cloud Messaging) but I have not been able to get the right response data through the Client. 我正在通过GCM(Google Cloud Messaging)发送以下JSON,但无法通过客户端获取正确的响应数据。 I get a push notification response, but the title is the App's name, and the texts reads: "message" so I can't display my notification properly. 我收到推送通知响应,但标题是应用程序的名称,并且文本显示为:“ message”,因此我无法正确显示通知。

Here is the JSON that I am trying to send: 这是我要发送的JSON:

{  
  "to": "somekey",
  "notification": {  
      "body":"Test",
      "title":"Test"
  },
  "data": null
}

I think that your problem is on the key-values of the payload of your message. 我认为您的问题出在您邮件有效负载的键值上。

As you can see at GCM Server documentation , the payload can be set using two different keys: 如您在GCM Server文档中所见,可以使用两个不同的键来设置有效负载

  • data : This parameter specifies the key-value pairs of the message's payload. data :此参数指定消息有效负载的键值对。
  • notification : This parameter specifies the key-value pairs of the notification payload. notification :此参数指定通知有效负载的键值对。

You should use the data key and set inside the payload of the notification. 您应该使用数据密钥并在通知的有效负载内进行设置。 Once send, you can print the result of the notification received and see that there are the right payload inside the data key. 发送后,您可以打印收到的通知的结果,并查看数据密钥内部是否有正确的有效负载。

Your message should be like the following JSON data: 您的消息应类似于以下JSON数据:

{
  "registration_ids" => "some_target_device_id",
  "data": {
      "title": "My title",
      "message": "This is the message!",
  }
}
Authorization: key= AIz......#GCM project key

{ "data": {
              "title": "Summer Offer.",
              "message": "Click to visit the offer."
          },
              "to" : "Device Token"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM