1

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.

sgosha
  • 1,299
  • 12
  • 19

2 Answers2

0

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

See more information here.

Mihai Fratu
  • 7,579
  • 2
  • 37
  • 63
  • I have tried calling `-[UIApplication cancelAllLocalNotifications]` both from `apllicationWillEnterForeground:` and `applicationDidBecomeActive:` methods but it didn't have the result I want. When application receives more than one incoming message and displays local notification alerts (not banners), those alerts are placed on top of each other. When I launch application from the latest alert, previous alert will be still visible either for a short second or forever. I want to dismiss previous alerts so that user doesn't see them. – sgosha Oct 21 '11 at 06:34
0

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

huesforalice
  • 2,418
  • 2
  • 24
  • 29