Dismiss local notifications when application becomes active

喜你入骨 提交于 2019-12-11 06:25:23

问题


I am developing an IM application that keeps connection open for some time when application is backgrounded and uses local notifications to alert user about new incoming messages.

Previously, on iOS 4, -[UIApplication cancelAllLocalNotifications] was called before presenting a new local notification using -[UIApplication presentLocalNotificationNow:]. This way always only the latest notification was present on the screen.

Since iOS 5 introduced Notification Center, this solution is not acceptable anymore because we want to have more that one last message displayed there. But also we want to close all local notification alerts when application becomes active. How do I better do that? I suppose I should call -[UIApplication cancelAllLocalNotifications] at some point, but I'm not sure where. Ahy help will be appreciated.


回答1:


Try calling -[UIApplication cancelAllLocalNotifications] in the apllicationWillEnterForeground method of your app delegate.

See more information here.




回答2:


Why not call -[UIApplication cancelAllLocalNotifications] in your applicationdelegates - (void)applicationDidBecomeActive:(UIApplication *)application method? That should be exactly what you're looking for.



来源:https://stackoverflow.com/questions/7841982/dismiss-local-notifications-when-application-becomes-active

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!