Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I want to have custom fields in the call.

I'm 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'm sending in the above:

{
   "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 ?

Thanks in advance !

like image 342
Ohad Greenshpan Avatar asked Nov 12 '22 08:11

Ohad Greenshpan


1 Answers

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

like image 159
Dima Avatar answered Nov 15 '22 05:11

Dima