Is there a way to programmatically remove/dismiss UILocalNotification
from Notification Tray.
I am able to cancel the notification which removes the notifications from
[[UIApplication sharedApplication] scheduledLocalNotifications]
Here is what i need to do
I need to dismiss the UILocalNotification
from NotificationTray after the action has been performed(ie after the user taps the notification)
EDIT:
I can remove the notifications from the NSNotificationCenter
. I want to remove specific notifications from the Notification Tray .Like the user presses the clear button to clear all the notifications belonging to a particular application.
You can cancel all notifications using:
[[UIApplication sharedApplication] cancelAllLocalNotifications];
If you want to remove a particular notification, you can use userinfo
of notification object, when you create a local notification add a unique ID to that. Later you can use that ID for removing local notification.
For that you can use the following code:
NSString *notificationId = @"id_to_cancel";
UILocalNotification *notification = nil;
for(UILocalNotification *notify in [[UIApplication sharedApplication] scheduledLocalNotifications])
{
if([[notify.userInfo objectForKey:@"ID"] isEqualToString:notificationId])
{
notification = notify;
break;
}
}
[[UIApplication sharedApplication] cancelLocalNotification:notification];