2

Let's say my app is running in the background, and I receive 2 local notifications at the same time. Alert1 for Notification1 shows, then Alert2 for Notification2 shows on top of Alert1. When I tap "View" for Alert2, my app enters the foreground, and didReceiveLocalNotification is called for Notification2, everything is all good.

However, Alert1 is still showing (since it was never closed or viewed). If I tap "View", nothing happens and as expected, didReceiveLocalNotification for Notification1 is NOT called.

Is there a way to either:

  1. clear all Alerts so that Alert1 is not shown when the app is entering foreground for Alert2
  2. handle the tap for "View" when Alert1 is pressed, since didReceiveLocalNotification is not called

Thanks!

4

1 回答 1

2

Calling cancelAllLocalNotifications also dismisses currently displayed alerts, even if the notification has already fired.

It's mentioned in the Local and Push Notification Programming Guide:

You can cancel a specific scheduled notification by calling cancelLocalNotification: on the application object, and you can cancel all scheduled notifications by calling cancelAllLocalNotifications. Both of these methods also programmatically dismiss a currently displayed notification alert.

Hence, I need to cancelAllNotifications and reschedule my current scheduled notifications. I tried cancelLocalNotification, but I don't have a reference to the notification because it no longer exists in the scheduledLocalNotifications array since it has already fired.

于 2011-04-22T21:17:29.127 回答