预定的本地通知在切换为closures时切换为开启时间段

每天早上八点半在下午一点钟通知你。

当“通知”在“设置”应用中closures一周时,通知不会显示,这是完美的。

问题是,在那个星期之后, 通知在“设置”应用程序中重新开启 ,前一周的所有通知都会显示出来

我想知道如何让通知不“build立”这么说。

是否有一行代码我错过了在这里“清除”?

ViewController.m

 - (void)viewDidLoad { [super viewDidLoad]; UILocalNotification* localNotification = [[UILocalNotification alloc] init]; NSCalendar *cal = [NSCalendar currentCalendar]; NSDateComponents *comp = [cal components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:[NSDate date]]; comp.hour = 20; // 19 = 7PM 20=8pm comp.minute = 30; // 7:45 PM 8:30 comp.second = 01; // 7:45:01 PM localNotification.fireDate = [cal dateFromComponents:comp]; localNotification.alertBody = @"Local Notification in iOS8"; localNotification.timeZone = [NSTimeZone defaultTimeZone]; localNotification.repeatInterval = NSCalendarUnitDay; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; } 

*这些是通知closures时显示的通知,只要我将通知切换回ON :*

在这里输入图像说明

当您将通知设置为OFF时,您应该调用[[UIApplication sharedApplication] cancelAllLocalNotifications];