views:

99

answers:

3

I'm trying to understand the applicationIconBadge property of UILocalNotification. I can only set an explicit badge value, I can't specify I just want it incremented when the notification fires.

http://developer.apple.com/iphone/library/documentation/iPhone/Reference/UILocalNotification_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40009565-CH1-SW11

I'm trying to accomplish the following: one notification fires, the user ignores it, a second notification fires, the user ignores it. At this point I would like the badge to be 2, but as far as I can tell there aren't any methods I can implement to handle the notification firing, but being ignored. My didReceiveLocalNotification event will not be called. That means there is no way for me to manipulate the badge number, aside from the UILocalNotification.applicationIconBadge property, which has no "just increment it" functionality.

+1  A: 

One way I can think of doing this is to maintain a count internally, and when you create each notification, assign it the right badge property. So if you know that notification 1 will fire before notification 2, then assign the first one 1, and the second one 2. This will take care of your issues as stated above.

If the user launches the app after notification 1 but before notification 2, and gets rid of the first '1' badge, then you can then reassign the badge properties for all the remaining notifications. It's more work than doing a straight += 1, but unless someone else has a better idea, I think this is the way to do it.

Simon
Thanks for the suggestions Simon. So is this just an oversight in the design of local notifications? The badge property seems fairly useless with this implementation.
Jeremy Mullin
It's probably just the minimum API needed to make notifications usable. I think the current implementation gives the developer more control of the badge, but I do agree it can be harder to use.
Simon
Thanks. Feels hokey, but I implemented your solution and it is working (I get list of all notifications, delete all, then add them with ascending badge property).
Jeremy Mullin
A: 

Hi simon....can you give me code for increasing the badge no by one.
I have tried to assign a count to application badge no.
I am using localNotification.repeatinterval....which run the app in background. i don't know which of the method is fired when the app received a notification while running from background.

A: 

I have reason to believe that the implementation of applicationIconBadgeNumber is buggy, or at least not according to what it has been described to do in the documentation.

I've filed a bug report/enhancement at http://bugreport.apple.com/

You may take a look at my report archived at Open Radar: http://openradar.appspot.com/radar?id=767401

Meanwhile, I have also resorted to a similar hackery just to achieve this simple behaviour.

According to Marco, developer of Instapaper, Apple prioritizes enhancement and feature requests partly based on how many developers are requesting them.

If this feature is important to you I urge you to file a report as well.

junjie