I have a app where the user has various events they are able to check into. If they check into the event, there will be a local notification setup for 24 hours before the event to remind the user. My question is, i have the setApplicationIconBadgeNumber for the app and i’m setting it to whatever the badge number is at the time, plus one. Problem is say that there’re two events that are at the same time, the badge number should be 2 not 1, how do I tell iOS to set the badge number appropriately? Since this is all local notification and happens at a particular time, its hard to keep track within code…
I have a app where the user has various events they are able to
Share
I agree it’s hard to keep track of in your code, especially since with local notifications your code might not have a chance to actually execute when this is all happening. Seems like an oversight in the API that could’ve been fixed with a special “increment badge number” event.
One solution is this: every time you create a new
UILocalNotification, go through the list of all existing notifications and figure out what each of them should have as the correct badge number (e.g., based on the fireDate of each).So, use
UIApplication‘sscheduledLocalNotificationsto get the array of existing applications. Sort them as necessary to figure out the correct badge number for each, and then update each object with the correct badge number. Set the (modified) array back as thescheduledLocalNotificationsproperty to register the updated values.Do the same thing whenever some unrelated external event changes the badge counter, and I think – though it’s not pretty – you should have a reliable hack.