How to cancel the day's recurring notifications in UserNotifications

276 Views Asked by At

I am developing a Todos App based on SwiftUI. It can notify users at a fixed time every day if they don't finish today's todos, I use the UserNotifications to implement the notification function. Currently I want to cancel the notification of the day if users finished their todos. So how can I implement based on UserNotifications?

1

There are 1 best solutions below

1
Konstantin Cherkashin On

To remove all at once:

UNUserNotificationCenter.current().removeAllPendingNotificationRequests()

To remove some separately:

  1. store ids of created notifications anywhere
  2. then call
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [<ids you want to cancel>])