Search code examples
iosiphoneusernotifications

Cancel and reschedule UserNotification(old UILocalNotification) starting from custom date in iOS 10


I'm scheduling a daily UserNorification to trigger everyday at a specific time, notifying the user to do something. But if the user does that X hours before the notification is fired, I need to cancel today's notification, in my opinion cancel all, and reschedule again but from tomorrow's specific time. For example, if today the notification should fire at 11:00 and the user "do that thing" at 10:00, the 11:00 notification should not be fired, and I need to schedule again at the same time but starting from tomorrow. And the cycle goes on and on, same for tomorrow. My questions are:

  1. Should I unschedule the first daily notifications using the following code: UNUserNotificationCenter.current().removeAllPendingNotificationRequests() ?

  2. How to schedule daily notifications starting from a specific date?


Solution

  • After researching, this is not possible with the new UserNotifications Framework. We must use the old UILocalNotification approach to achieve this. Because that code is deprecated in iOS10, I've changed the supported version to be from 9+, so there will be no warnings. This is a permanent approach, but lets hope that Apple will implement and extend the old feature in the new framework.