Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to cancel a local notification in iphone

Tags:

iphone

I am making the application that has needs to set the notification , thankfully i was able t set the local notification but i dont know how to delete the notification which is set by this application(my aplicaton ).The xcode does provide functionality of delete with removeAllNotifications but you cannot remove the selected notifications set by the application

like image 723
mrugen munshi Avatar asked Jul 31 '10 17:07

mrugen munshi


2 Answers

You can call [[UIApplication sharedApplication] cancelLocalNotification:notification] to cancel a notification. Since local notifications conform to the NSCoding protocol, they can be stored and retrieved for later canceling.

like image 154
Ed Marty Avatar answered Sep 25 '22 02:09

Ed Marty


I know this post is old but hope this solution helps someone

NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
    for(UILocalNotification *notification in notificationArray){
        if ([notification.alertBody isEqualToString:@"your alert body"]  && (notification.fireDate == your alert date time)) {
            // delete this notification
            [[UIApplication sharedApplication] cancelLocalNotification:notification] ;
        }
    }

I am comparing the alert body and date time just to make sure that i am deleting the right notification since there are chances where two or more notifications can have the same alert body or time.

like image 27
NSDumb Avatar answered Sep 24 '22 02:09

NSDumb