I have a watch application that shows (local) notifications to users at scheduled time. The notifications are "reminders" to the user like "Hey, task xyz is coming up in 5 minutes".... or something to that effect.
I have the notifications working properly and everything.
What I want to do now is, if the person marked a particular "Task xyz" as "completed" before the notification even fired, then I don't want to show that notification.
1 way is whenever the user marks "Task xyz - completed", I can use removeAllPendingNotificationRequests()
and after that reschedule all the notifications based on my flag "is_complete?". This is not a really good way because I don't reschedule everything everytime 1 task gets completed.
What I really want to do is, when the scheduled notification's trigger time has come, I want to call a function that checks the "is_complete?" flag and if it is true, the notification isn't fired and otherwise, it is fired.
I found 2 functions:
-
When the app isn’t running, i.e. it’s in the background or closed, the delegate function userNotificationCenter(_:didReceive:withCompletionHandler:)
is called after the user taps on it.
-
When the app is running and in the foreground, using the delegate function userNotificationCenter(_:willPresent:withCompletionHandler:)
is only called when the app is in the foreground.
So, they don't help.
Is it possible to call a function or perform an action right before a notification is fired?