Swift 更改将重复UNTimeIntervalNotificationTrigger的值

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

我有一个本地通知,我每60秒重复一次:

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()取消所有本地通知