iOS 10 User Notifications does not allow repeating of notifications at intervals

Originator:mail.junjie
Number:rdar://26855019 Date Originated:17-Jun-2016 10:46 AM
Status:Open Resolved:
Product:iOS SDK Product Version:iOS 10 Beta 1
Classification:Serious Bug Reproducible:Not Applicable
 
With the new iOS 10 User Notifications framework, one can no longer schedule notifications at a specific date or time that repeats every minute or every hour.

For instance, before iOS 10, one could schedule a notification at 7 AM tomorrow that repeats every minute with the following code:

	let dateFlags: NSCalendarUnit = [.Year, .Month, .Day, .Hour, .Minute]
	let nowComps = NSCalendar.currentCalendar().components(dateFlags, fromDate: NSDate.init())
	let tomorrowComps = nowComps.copy() as! NSDateComponents
	tomorrowComps.day += 1
	tomorrowComps.hour = 7
	tomorrowComps.minute = 0
	let dateAt7AMTomorrow = NSCalendar.currentCalendar().dateFromComponents(tomorrowComps)

	let notification = UILocalNotification()
    notification.fireDate = dateAt7AMTomorrow
    notification.alertBody = "Wake up!"
    notification.soundName = UILocalNotificationDefaultSoundName
    notification.repeatInterval = .Minute
    UIApplication.sharedApplication().scheduleLocalNotification(notification)

In the new framework, one would create a UNCalendarNotificationTrigger with the date components at 7 AM tomorrow, but there is no way to specify that the notification should repeat at a custom interval of every minute because the repeats option is a simple boolean.

	let trigger = UNCalendarNotificationTrigger.init(dateMatchingComponents: tomorrowComps, repeats: true)
	
Using a UNTimeIntervalNotificationTrigger wouldn't work either.
	
This means that a simple use case such as an alarm that snoozes once every minute cannot be achieved with the new framework.

In session 707 of WWDC 2016, iOS Notifications Engineer Kritarth Jain introduced the new User Notifications framework as something with "feature parity with what exists today, so transferring your code from the existing API to the new framework will be very easy."

However, the new framework does not have feature parity with the existing API in terms of scheduling recurring notifications.

There is no way for apps to adopt the new User Notifications framework if they rely on NSCalendarUnit to specify a custom repeat interval independent of the trigger date.

For reference, the OS X NSUserNotification API introduced in OS X 10.8 features a much better way to specify the recurrence of a notification by separating the deliveryDate from the deliveryRepeatInterval. 

The deliveryRepeatInterval specifies "the date components that control how often a user notification is repeated".

This improves on UILocalNotification by not only allowing a notification to repeat every 1 calendar unit, but also every N calendar unit of time.

A wake up alarm can then repeat every 9 minutes instead of every minute with the OS X API.

However, in the new iOS 10 User Notifications framework, there is no way to achieve either.

It's great to see Apple rethinking the notifications framework given that it has not changed since iOS 4. However, dropping support for custom repeat interval is a step backwards.

A suggestion to adopt feature parity with UILocalNotification would be to change the repeats parameter in both UNCalendarNotificationTrigger and UNTimeIntervalNotificationTrigger from a Bool to a NSCalendarUnit. However, to improve it further, the repeats parameter can become a NSDateComponent similar to OS X NSUserNotification's implementation, which allows for even more flexibility in repeating a notification.

	UNCalendarNotificationTrigger.init(dateMatching: DateComponents, repeatInterval: DateComponents)
	UNTimeIntervalNotificationTrigger.init(timeInterval: TimeInterval, repeatInterval: DateComponents)

Comments

+1 The problem is still there.. no sign of life?

By decrecchio.ernesto at Aug. 28, 2019, 9:50 a.m. (reply...)

+1. Guys, really, its 21st century. Fix that, please

By tov.komarov at Nov. 1, 2017, 10:32 p.m. (reply...)

Still there in iOS11 :(

By zulfishah at June 6, 2017, 4:30 p.m. (reply...)

Agree. +1 vote for fixing this.

By leo.tumwattana at Oct. 13, 2016, 9:23 p.m. (reply...)

This bug is replicable and should be fixed.

By littlebluedot2016 at Sept. 7, 2016, 5 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!