Is it possible to have a short evaluation process happen before a local notification is being presented?
Depending on the outcome of this evaluation, I would then cancel/remove a potentially unnecessary notification.
Is it possible to have a short evaluation process happen before a local notification is being presented?
Depending on the outcome of this evaluation, I would then cancel/remove a potentially unnecessary notification.
Yes it is. Note that mentioning:
Is it possible to have a short evaluation process happen before a local notification is being presented?
Means that the notification status is Pending.
So what you should do is to call removePendingNotificationRequests(withIdentifiers:) and passing the notification identifier(s) to it that you want it/them to be removed.
You could implement it like this:
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: ["notificationID"])
and that should do the job.
Note that it takes identifiers
as an array of strings, even if your need is to remove only one notification, you would need to pass an array containing one string.
Obviously, "notificationID" is the used identifier for your notification that you are using when you registering it (when creating the UNNotificationRequest
):
// ...
let request = UNNotificationRequest(identifier: "notificationID", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request)