這就是我做的。
創(chuàng)建通知時,請執(zhí)行以下操作:
// Create the notificationUILocalNotification *notification = [[UILocalNotification alloc] init] ;notification.fireDate = alertDate;notification.timeZone = [NSTimeZone localTimeZone] ;notification.alertAction = NSLocalizedString(@"Start", @"Start");notification.alertBody = **notificationTitle**;notification.repeatInterval= NSMinuteCalendarUnit;notification.soundName=UILocalNotificationDefaultSoundName;notification.applicationIconBadgeNumber = 1;[[UIApplication sharedApplication] scheduleLocalNotification:notification] ;
當(dāng)試圖刪除它時,請執(zhí)行以下操作:
NSArray *arrayOfLocalNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications] ;for (UILocalNotification *localNotification in arrayOfLocalNotifications) {
if ([localNotification.alertBody isEqualToString:savedTitle]) {
NSLog(@"the notification this is canceld is %@", localNotification.alertBody);
[[UIApplication sharedApplication] cancelLocalNotification:localNotification] ; // delete the notification from the system
}}
此解決方案應(yīng)適用于多個通知,并且您不管理任何陣列或字典或用戶默認(rèn)值。您只需使用已保存到系統(tǒng)通知數(shù)據(jù)庫的數(shù)據(jù)即可。
希望這有助于未來的設(shè)計(jì)師和開發(fā)者