gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:15:54 27 4
gpt4 key购买 nike

我在晚上 8:30:01 有一个每日预定通知

当“设置”应用中的通知被关闭切换一周后,没有通知显示,这很完美。

问题是当通知在该周之后在“设置”应用中切换回ON时,前一周的所有通知都会显示 .

我想知道如何让通知不“累积”可以这么说。

这里是否缺少一行代码来“清除它们”?

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

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

enter image description here

最佳答案

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

关于ios - 计划的本地通知在切换为 ON 的时间段内显示,切换为 OFF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29956882/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com