scheduledLocalNotifications array will show as empty even if you have set local notifications
. 最好的方法是保留单独的本地通知对象。这样您就可以轻松删除它。
设置本地通知时,像这样保存对象
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
NSString *userDefKey = @"key";
NSData *dataEnc = [NSKeyedArchiver archivedDataWithRootObject:localNotification];
[[NSUserDefaults standardUserDefaults] setObject:dataEnc forKey:userDefKey];
你应该保留钥匙
当您要删除特定的本地通知时
if([[NSUserDefaults standardUserDefaults] objectForKey:userDefKey]){
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:userDefKey];
UILocalNotification *localNotif = [NSKeyedUnarchiver unarchiveObjectWithData:data];
[[UIApplication sharedApplication] cancelLocalNotification:localNotif];
}