How can I send a push notification with custom Java fields?

I am trying to send a push notification from a Java server to our Corona-based mobile client. I want to have custom fields in a call.

I am using the following (javapns library)

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

This is the json I am sending above:

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

For some reason, it does not come in the user field.

Can someone help me with an example for such a json to send?

Thanks in advance!

+5
source share
1 answer

you can just use

PushNotificationPayload payload = PushNotificationPayload.complex();

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

exactly as per javapns instructions

+1
source

All Articles