Local notification: repeat functionality not working as expected

227 views Asked by At

Working on an alarm app and trying to repeat alarm weekly using the below code:

if repeatWeekly {
    let triggerWeekly = (Calendar.current as NSCalendar).components([.weekOfYear, .hour, .minute, .second], from: currentDateTime)
    trigger = UNCalendarNotificationTrigger(dateMatching: triggerWeekly, repeats: true)
} else {
    let triggerDaily = (Calendar.current as NSCalendar).components([.hour,.minute,.second,], from: currentDateTime)
    trigger = UNCalendarNotificationTrigger(dateMatching: triggerDaily, repeats: false)
}

In iOS9 using UILocalNotification it is working fine with the following code:

let localNotification = UILocalNotification()
localNotification.repeatInterval = NSCalendar.Unit.weekOfYear

But in iOS10 using UNUserNotification repeat local notification doesn't work properly, it only repeats for 1 week and never shows up for the next week.

For example, if current date time is "1 Sept 2017" then notification will be repeated for "8 Sept 2017" but not repeated for 15 Sept, 22 Sept or so on.

Thanks

0

There are 0 answers