iphone - UILocalNotification is not getting cancelled -
i trying cancel scheduled notification , notification getting called when try cancel notification not getting cancelled .
nsarray notification contains random values when there 1 scheduled notification. can me . want cancel notification 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]; (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]; (uilocalnotification *notification in notifications) { int notifbookid = [[notification.userinfo objectforkey:kremindmenotificationbookidkey] intvalue]; (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]; } } }
nsarray notification contains random values when there 1 scheduled notification.
it may due scheduled notifications of application exists. once try cancel notifications of app starts again
[[uiapplication sharedapplication] cancelalllocalnotifications];
your main problem
- (void)cancelnotification:(int)remedyid { nsarray *notifications = [[uiapplication sharedapplication] scheduledlocalnotifications]; nslog(@"cancelling... before %d",[[[uiapplication sharedapplication]scheduledlocalnotifications]count]); (uilocalnotification *notification in notifications) { int notifremedyid = [[notification.userinfo objectforkey:@"kremindmenotificationremedyidkey"]intvalue]; // change key value nslog(@"remedyid : %d",remedyid); nslog(@"notifyid : %d",notifremedyid); if (remedyid == notifremedyid) { [[uiapplication sharedapplication] cancellocalnotification:notification]; } } nslog(@"cancelling... after %d",[[[uiapplication sharedapplication]scheduledlocalnotifications]count]); }
the key have given wrong. think problem. figured out 1 more thing scheduling each notification twice dont know why. check that.
Comments
Post a Comment