有没有办法暂停一个实例的重复通知?

Is there a way to pause a repeating notification for one instance?

我希望能够暂停一次循环通知,需要触发的时候,我希望它触发。我知道 removeAllPendingNotifications。但不确定是否可以解决问题,因为它似乎已将其完全删除。你有什么想法?

您可以使用 getPendingNotificationRequests 和 select 您需要取消的标识符,然后将它们传递给 removePendingNotificationRequests(withIdentifiers: [String])

UNUserNotificationCenter.current().getPendingNotificationRequests { (reqs) in
   var ids =  [String]()
   reqs.forEach {
       if [=10=].identifier == "someId" {
          ids.append([=10=].identifier)
       }
   }
   UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers:ids)
}

`

我的解决方案是使用上面的代码删除当天的通知,或者只知道标识符并删除待处理的通知标识符。然后将通知添加回去,但要在第二天添加。

即一个例子就像一个有重复任务但不想收到任务完成通知的应用程序。

这个Whosebug作为代码:Scheduling local notifications to repeat daily from tomorrow in Swift