I know similar questions appeared before but I think I need more clarification since i still don't know how to make it done. I'm a beginner programmer so please forgive me any mistakes.
I'm trying to have daily reminders for daily tasks from my app IF user didn't complete it yet, so how can i make it not show up when he had already done the task?
Solutions i found so far suggest to remove pending notification and setting up new one for future date in the same time.
I successfully set up daily notifications using this code:
func sendDailyReminder() {
let content = UNMutableNotificationContent()
content.title = "Daily reminder"
content.body = "You still have task to complete today."
content.sound = UNNotificationSound.default
var dateComponents = DateComponents()
dateComponents.hour = 20
dateComponents.minute = 00
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
let request = UNNotificationRequest(identifier: "dailyTrigger", content: content, trigger: trigger)
center.add(request) { (error) in
if let error = error {
print("Notification Error: ", error)
}
}
}
i can also successfully remove pending notification with removePendingNotificationRequest method but how can I set it up trigger for tomorrow using dateComponents here?
Or is there any other way to achieve that? Maybe using background fetch to check if its done just before sending notification?
Some replies i found suggest that its actually impossible but then how any task or to-do app can achieve something like that?