Handling notification alerts that fire when the app is not running, but still show when the app is running
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, everythi开发者_JAVA技巧ng 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:
- clear all Alerts so that Alert1 is not shown when the app is entering foreground for Alert2
- handle the tap for "View" when Alert1 is pressed, since
didReceiveLocalNotification
is not called
Thanks!
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.
精彩评论