Wednesday, May 22, 2013

cancelLocalNotification example UIApplication ios


[UIApplication cancelLocalNotification]

Cancels the delivery of the specified scheduled local notification.
- (void)cancelLocalNotification:(UILocalNotification *)notification
Parameters
notification
The local notification to cancel.
Discussion of [UIApplication cancelLocalNotification]
Calling this method also programmatically dismisses the notification if it is currently displaying an alert.
Example of [UIApplication cancelLocalNotification]
UIApplication *app = [UIApplication sharedApplication];
NSArray *eventArray = [app scheduledLocalNotifications];
for (int i=0; i<[eventArray count]; i++)
{
    UILocalNotification* oneEvent = [eventArray objectAtIndex:i];
    NSDictionary *userInfoCurrent = oneEvent.userInfo;
    NSString *uid=[NSString stringWithFormat:@"%@",[userInfoCurrent valueForKey:@"uid"]];
    if ([uid isEqualToString:uidtodelete])
    {
        //Cancelling local notification
        [app cancelLocalNotification:oneEvent];
        break;
    }
}
Example of [UIApplication cancelLocalNotification]
NSData *data= [[NSUserDefaults standardUserDefaults] objectForKey:[NSString   stringWithFormat:@"%d",UniqueKey]];

UILocalNotification *localNotif = [NSKeyedUnarchiver unarchiveObjectWithData:data];
NSLog(@"Remove localnotification  are %@", localNotif);
[[UIApplication sharedApplication] cancelLocalNotification:localNotif];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:[NSString stringWithFormat:@"%d",UniqueKey]];
Example of [UIApplication cancelLocalNotification]
NSString *myIDToCancel = @"some_id_to_cancel";
UILocalNotification *notificationToCancel=nil;
for(UILocalNotification *aNotif in [[UIApplication sharedApplication] scheduledLocalNotifications]) {
  if([aNotif.userInfo objectForKey:@"ID"] isEqualToString:myIDToCancel]) {
     notificationToCancel=aNotif;
     break;
  }
}
[[UIApplication sharedApplication] cancelLocalNotification:notificationToCancel];