Question

I've implmented a simple server for pushing notifications to iOS devices and I can't imagine how to handle badges. I've read some topics and all I know that it's not a good solution to handle them manually on device, that it's the server job...

Everything is clear but I still don't know and couldn't find anywhere how I to let the server know that there are some unreaded notifications on my device? I mean where in UIApplicationDelegate is info about beeing read?

Just to help you guys imagine my problem:

  1. Application is running in foreground and receives push notification.
  2. User doesn't enter app so the badge is visible.
  3. After 5 mins comes another notification (again with badge value set to 1 in payload).

And this scenario could happen many times but the APNS is still pushing payload with the same value for badge.

Was it helpful?

Solution

The number of badges can be obtained from method

[application applicationIconBadgeNumber]

inside application:didFinishLaunchingWithOptions: method.

Hope this helps!

UPDATE:

After clarifying the question, I'll update the answer with accepted solution. For future searchers:

what if the backend would increase the badge every time when the notification will be sent? for example, You send first notification with badge count 1. Then it's time to send another notification - you send it with badge count 2. Then user opens the app and makes API call to the backend - and you zero-out the badge count, and the next notification would be send with badge count 1. If app get's notification in foreground, it makes the api call immediately and you zero-out the badge count immediately as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top