开发者

How can I increment app icon badge when multiple local notifications fire?

I'm trying to understand the applicationIcon开发者_如何学GoBadge 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.


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.


Check out this category I made for UILocalNotification: GitHub UILocalNotification


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜