The same UNNotification is the base for the identifier passed when creating the UNNotificationRequest .
In the example above
let request = UNNotificationRequest(identifier: "myNotif", content: notif, trigger: dateTrigger)
You really have hardcoded identifier as "myNotif" . Thus, whenever you want to delete an already installed notification, you can do this:
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: "myNotif")
However, note that with hard-coded identifiers every time you add request to UNUserNotificationCenter , the notification is actually replaced.
For example, if you scheduled the "myNotif" request install 1 minute later, but you call another function to schedule the "myNotif" 1 hour later, it will be replaced. Therefore, only the last "myNotif" in an hour will be in pendingNotificationRequest .
source share