只是讓它們具有「日期」,「isCanceled」字段和唯一id「alarmId」列(無論你想使用REST)的數據庫表。因此,當用戶想要取消報警試試這個,
NSString *alarmId = @"some_id_to_cancel";
UILocalNotification *notificationToCancel=nil;
for(UILocalNotification *aNotif in [[UIApplication sharedApplication] scheduledLocalNotifications]) {
if([aNotif.userInfo objectForKey:@"ID"] isEqualToString:alarmId]) {
notificationToCancel = aNotif;
break;
}
}
[[UIApplication sharedApplication] cancelLocalNotification:notificationToCancel];
使用這個更好的,你創建你的報警,
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = itemDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertAction = NSLocalizedString(@"View Details", nil);
localNotif.alertBody = title;
localNotif.soundName = UILocalNotificationDefaultSoundName;
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:stringID forKey:@"ID"];
localNotif.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];