Undo and migrate UserNotification (old UILocalNotification) starting from user date in iOS 10

I plan to UserNorificationrun every day at a specific time every day, telling the user to do something. But if the user does this 8 hours before the notification is dismissed, I need to cancel the notification today, in my opinion, cancel everything, and also reschedule again, but from tomorrow. For example, if today the notification should be sent at 11:00, and the user "will do it" at 10:00, the notification should not be fired 11:00, and I will need to schedule again at the same time, but starting tomorrow And the cycle goes on and on, the same for tomorrow. My questions:

  • Should I turn off the first daily notifications using the following code UNUserNotificationCenter.current().removeAllPendingNotificationRequests():?

  • How do I schedule daily notifications starting from a specific date?

+4
source share
2 answers

After research, this is not possible with the new UserNotificationsFramework. To do this, we must use the old approach UILocalNotification. Since this code is deprecated in iOS10, I changed the supported version to 9+, so there will be no warnings. This is an ongoing approach, but it is hoped that Apple will implement and expand the old function in the new structure.

+1
source

, iOS 10. , - , - UNCalendarNotificationTrigger, UNTimeIntervalNotificationTrigger a UNNotificationContentExtension.

:

, , . (, 11:00 ), , , , ( tempNotification)

let nextDayAt11AMDate = /* the timestamp of tomorrow at 11am */
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: nextDayAt11AMDate.timeIntervalSinceDate(NSDate()), repeats: false)
/* schedule tempNotification */

( , UNNotificationContentExtension ), didReceive:, , , , , ( actualNoticfication)

let date = DateComponents()
date.hour = 11
date.minute = 00 
let trigger = UNCalendarNotificationTrigger(dateMatching: date, repeats: true)
/* schedule actualNotification */

, , , 100% (, , tempNotification, actualNotification ), , , ...

+3

Source: https://habr.com/ru/post/1664064/


All Articles