【问题标题】:changing repeats value of UNTimeIntervalNotificationTrigger更改 UNTimeIntervalNotificationTrigger 的重复值
【发布时间】:2017-11-22 05:07:03
【问题描述】:

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

var trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true);

如果满足某个条件,我想将UNTimeIntervalNotificationTriggerrepeats 值从true 更改为false,即:

if (condition) {
    trigger!.repeats = true;
}

但这似乎不起作用,因为我认为在创建对象后我无法更改 repeats 值。

有什么方法可以做我想做的事吗?

【问题讨论】:

  • 如果满足条件,您可以使用truefalse创建另一个。此外,您应该取消较旧的通知。

标签: swift repeat localnotification


【解决方案1】:

您可以将本地通知删除为

UIApplication.shared.cancelAllLocalNotifications()

如果你想再次true 然后再次分配

trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true)

可能是这个作品

【讨论】:

  • 这是 iOS 10!您可以取消来自UNUserNotificationCenter的所有本地通知
  • UNUserNotificationCenter.current().removeAllPendingNotificationRequests() UNUserNotificationCenter.current().removeAllDeliveredNotifications()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-02
  • 2020-09-01
  • 2021-05-27
  • 2021-10-17
  • 2015-02-07
  • 1970-01-01
相关资源
最近更新 更多