javaiosapachenotificationsjavapns

How to add a JSON to payload in JavaPNS push notification?


I want to add a JSON with the notification. I can send alert now. How can I send a JSON with the notification?

Code snippet I'm currently Using:

PushNotificationPayload payload = PushNotificationPayload.complex();
payload.addAlert("Hello!!!");
payload.addBadge(1);
payload.addSound("default");
payload.addCustomDictionary("id", "1");
List<PushedNotification> NOTIFICATIONS = Push.payload(payload, "D:\\ios_dev.p12", "1234", true, "b3ead5d64ba0e08241e236f3ee041d8a9f036b39a0b0537e99a5f8b0607");

for (PushedNotification NOTIFICATION : NOTIFICATIONS) {
  if (NOTIFICATION.isSuccessful()) {
     System.out.println("PUSH NOTIFICATION SENT SUCCESSFULLY TO: " + NOTIFICATION.getDevice().getToken());
  }
}

I want to add JSON like:

{
  "message": message,
  "m_id": mId,
  "callNo": callNo
}

How can I pass this?


Solution

  • I found the solution for you.

    PushNotificationPayload payload=PushNotificationPayload.fromJSON("{\"aps\":{\"content-available\":1,\"sound\":\"\",\"alert\":\"Some alert\"}}");
    

    Only take a String, create the JSON object and pass as String to 'PushNotificationPayload.fromJSON'

    It works for me :)