I am trying to cancel a already scheduled notification , notification is getting called but when i try to cancel a notification its not getting cancelled .
NSArray notification contains some random values when there is only one scheduled notification. can anyone help me . I am want to cancel the notification for a particular bookID.
UPDATE :
-(UILocalNotification *)scheduleNotification :(int)remedyID
{
NSString *descriptionBody;
NSInteger frequency;
UILocalNotification *notif = [[UILocalNotification alloc] init];
NSLog(@"%d",remedyID);
descriptionBody =[[self remedyDetailsForRemedyID:remedyID] objectForKey:@"RemedyTxtDic"];
frequency = [[[self remedyDetailsForRemedyID:remedyID] objectForKey:@"RemedyFrequency"]intValue];
NSArray *notificationFireDates = [self fireDatesForFrequency:frequency];
for (NSDate *fireDate in notificationFireDates)
{
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.repeatInterval = NSDayCalendarUnit;
notif.alertBody = [NSString stringWithString:descriptionBody];
notif.alertAction = @"Show me";
notif.soundName = UILocalNotificationDefaultSoundName;
notif.applicationIconBadgeNumber = 1;
notif.fireDate = fireDate;
NSDictionary *userDict = [NSDictionary dictionaryWithObjectsAndKeys:notif.alertBody, @"kRemindMeNotificationDataKey", [NSNumber numberWithInt:remedyID],kRemindMeNotificationRemedyIDKey,
nil];
notif.userInfo = userDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
}
return notif;
}
- (void)cancelNotification:(int)bookID
{
int notificationBook=0;
NSArray *notifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
for (UILocalNotification *notification in notifications)
{
int notifBookId = [[notification.userInfo objectForKey:kRemindMeNotificationBookIDKey] intValue];
for (int i=0; i<[bookArray count]; i++)
{
notificationBook =[[[remedyArray objectAtIndex:i] objectForKey:@"BookID"] intValue];
}
NSLog(@"%d",[[notification.userInfo objectForKey:kRemindMeNotificationBookIDKey]intValue]);
NSLog(@"%d",notifBookId);
if (bookId == notifBookId)
{
[[UIApplication sharedApplication] cancelLocalNotification:notification];
}
}
}