2

I am using java-apns library. JavaDoc for method badge from PayloadBuilder class states that:

Sets the notification badge to be displayed next to the application icon. The passed value is the value that should be displayed (it will be added to the previous badge number), and badge of 0 clears the badge indicator.

However, passing always 1 to method does not increment badge number on application icon. It's stuck on 1 (or on the number I pass).

Is it possible to solve that or documentation is wrong? I do not want to keep server-side how many unread notifications are on client and manage that number on my own as work-around. Since I know that notifications can be discarded by Apple if device is not reachable for a long time and so is easy to get out of synch.

An example of my code:

PayloadBuilder payloadBuilder = APNS.newPayload().alertBody("Test message");
payloadBuilder.actionKey("OK");
payloadBuilder.badge(1);

and JSON payload from console:

Payload={"aps":{"alert":{"body":"Test message","action-loc-key":"OK"},"badge":1}}
giampaolo
  • 6,906
  • 5
  • 45
  • 73

1 Answers1

1

you need to include the "badge" in your payload, it doesn't get accumulated.

I guess you need to set: payloadBuilder.badge(15); // 15 is the total

See this apple doc.

Tarek Hallak
  • 18,422
  • 7
  • 59
  • 68
  • 1
    I can tell man, but the device updates the badge according to the "badge" value in the payload, so I don't think the library you use has anything to do rather than creating the payload and send it. – Tarek Hallak Aug 14 '13 at 15:54
  • 1
    Looking also at this http://stackoverflow.com/questions/1942605/push-notification-badge-auto-increment, it seems that it's not possible at all. – giampaolo Aug 14 '13 at 16:07
  • You can't increment the badge number, only set it. They probably did this because it's a bad idea to increment it anyway since push notifications aren't always received. You should track the number server-side. – sudo Mar 07 '14 at 20:52