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

时间:2015-04-30 00:20:08

标签: ios objective-c xcode notifications uilocalnotification

我在8:30:01 PM有每日预定通知

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

问题是在该周之后在“设置”应用中将通知切换回 ON 显示上周的所有通知

我想知道如何获取通知而不是#34;积累"可以这么说。

我是否遗漏了一行代码"清除它们"?

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 时显示的,只要我将通知切换回开启:*

enter image description here

1 个答案:

答案 0 :(得分:1)

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