Swift 更改将重复UNTimeIntervalNotificationTrigger的值
我有一个本地通知,我每60秒重复一次:Swift 更改将重复UNTimeIntervalNotificationTrigger的值,swift,repeat,localnotification,Swift,Repeat,Localnotification,我有一个本地通知,我每60秒重复一次: var trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true); 如果满足某个条件,我想将直到IntervalNotificationTrigger的repeats值从true更改为false,即: if (condition) { trigger!.repeats = true; } 但是,这似乎不起作用,因为我认为在创建对象后无法更改repea
var trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true);
如果满足某个条件,我想将直到IntervalNotificationTrigger
的repeats
值从true
更改为false
,即:
if (condition) {
trigger!.repeats = true;
}
但是,这似乎不起作用,因为我认为在创建对象后无法更改repeats
值
是否有任何方法可以执行我尝试执行的操作?您可以删除本地通知,如下所示:
UIApplication.shared.cancelAllLocalNotifications()
如果要再次true
,请再次分配
trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true)
可能是这项工作如果满足条件,您可以使用
true
或false
创建另一项。你也应该取消一个旧的通知。这是一个iOS 10!您可以从UNUserNotificationCenter
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()UNUserNotificationCenter.current().removeAllDeliveredNotifications()取消所有本地通知