当多个本地通知触发时,如何增加应用程序图标徽章? [英] How can I increment app icon badge when multiple local notifications fire?

查看:117
本文介绍了当多个本地通知触发时,如何增加应用程序图标徽章?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解UILocalNotification的applicationIconBadge属性。我只能设置一个明确的徽章值,我不能指定我只是希望它增加时,通知触发。

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

我尝试完成以下操作:一个通知触发,用户忽略它,火灾,用户忽略它。在这一点上,我想徽章是2,但据我所知,没有任何方法可以实现来处理通知的触发,但被忽略。我的didReceiveLocalNotification事件不会被调用。这意味着除了UILocalNotification.applicationIconBadge属性,我没有办法操作徽章编号,它没有只是增加它功能。

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将在通知2之前触发,然后分配第一个1,第二个。这将照顾你的问题,如上所述。

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.

如果用户在通知1之后但在通知2之前启动应用程序,并移除了第一个1徽章,则可以重新分配所有剩余通知的徽章属性。这比直接做+ = 1更多的工作,但除非有更好的想法,我认为这是做的方式。

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.

这篇关于当多个本地通知触发时,如何增加应用程序图标徽章?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆