Is it possible to do this? UIApplication's scheduledLocalNotifications doesn’t seem to return notifications that have already been delivered to the user’s notification center, so I think this may be by design, but I can’t find any documented evidence of this.
Anyone know?
Thanks!
EDIT: Found this:
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
However, how do I get a reference to an already-delivered notification, if scheduledLocalNotifications doesn’t give me notifications that have already been delivered?
EDIT 2:
Here’s what I’m trying to do, after I’ve registered some notifications:
UIApplication *app = [UIApplication sharedApplication];
for (UILocalNotification *localNotification in app.scheduledLocalNotifications)
{
if (someCondition) {
[app cancelLocalNotification:localNotification];
}
}
}
The problem is that once they’re delivered, they’re no longer in ‘scheduledLocalNotifications’.
You can solve this by adding your newly created notifications to your own
NSMutableArrayof notifications and check that array instead ofapp.scheduledLocalNotifications.Something like this:
Add a
NSMutableArrayto your Viewcontrollers .h file:Initiate it when initiating your ViewController
When initiating a notification, also add it to your array:
Later when you want to cancel that notification, look for it in your array instead.
Also remove it from your array: