问题
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