ViS ViS - 7 months ago 35
Java Question

how to send content-available = 1 from javapns

I am using java client to send notifications using javapns. But now I need to notify the client application about the new notification using "content-available": 1, so that the app can raise a flag of content available at its end.

So far I have been using a similar code to one below,

PushNotificationPayload payload = PushNotificationPayload.complex();

payload.addAlert(apnsUser.getPushMessage());
payload.addSound("default");
payload.addCustomDictionary("someKey", someValue);

List<ListNotification> notifications = Push.payload(payload, somekeyStore, somepassword, isproduction, threads, devices);


But the payload class does not have a place holder for "content-available": 1.
I also checked for

Push.contentAvailable(keystore, vKeyStoreName, production, devices)


but it does not allow setting custom message value "someKey".

Please suggest a way to send "content-available": 1 while triggering notification.

ViS ViS
Answer

Sorry for posting my answer so late, i figured it out back then. Its quite simple.

  JSONObject vSomeDictionary = new JSONObject();
  vSomeDictionary.put("content-available", 1);
  vSomeDictionary.put("alert", "SomeMessage");
  vSomeDictionary.put("sound", "default");
  JSONObject vJPayload = new JSONObject();
  vJPayload.put("aps", vSomeDictionary);

This way you can set the content-available, by creating two different Jso objects and fitting one into another as "aps".