简体   繁体   English

如何使用Java中的自定义字段发送推送通知?

[英]How can I send a push notification with custom fields from Java?

I'm trying to send a push notification from a Java server to our Corona-based mobile client. 我正在尝试从Java服务器向基于Corona的移动客户端发送推送通知。 I want to have custom fields in the call. 我想在通话中有自定义字段。

I'm using the following (javapns library) 我正在使用以下(javapns库)

String rawJSON = "{\"aps\": {\"badge\": 10,\"alert\": \"test\",\"sound\": \"cat.caf\"},\"custom\":{\"id\":8}}";
PushNotificationPayload payload = PushNotificationPayload.fromJSON(rawJSON);

This is the json I'm sending in the above: 这是我在上面发送的json:

{
   "aps":{
      "badge":10,
      "alert":"test",
      "sound":"cat.caf"
   },
   "custom":{
      "id":8
   }
}

For some reason, it doesn't arrive in the custom field. 由于某种原因,它不会到达自定义字段。

Can anyone help me with an example for such json that needs to be sent ? 任何人都可以帮助我找一个需要发送的json的例子吗?

Thanks in advance ! 提前致谢 !

you can just use 你可以使用

PushNotificationPayload payload = PushNotificationPayload.complex();

payload.addAlert("Hello World!");
payload.addCustomDictionary("mykey1", "My Value 1");
payload.addCustomDictionary("mykey2", 2);

exactly as instructed at javapns 完全按照javapns的指示

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

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