计划的本地通知在切换为 ON 的时间段内显示,切换为 OFF

Scheduled Local Notifications showing up when toggled ON for time period when toggled OFF

我在 8:30:01 下午有一个每日预定通知

当在“设置”应用中将通知切换为 关闭 一周后,没有显示任何通知,这很完美。

问题是当通知在那个星期后在“设置”应用中切换回 ON 时,所有通知上周出现.

我想知道如何让通知不 "build up" 可以这么说。

"clear them out"这里有我遗漏的代码行吗?

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];
}

*这些是从通知 OFF 开始显示的通知,只要我将通知切换回 ON :*

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