iOS 10: UIApplication.scheduledLocalNotifications blocking main thread for up to 10s

Originator:mail.junjie
Number:rdar://27944179 Date Originated:22-Aug-2016 04:20 PM
Status:Open Resolved:
Product:iOS Product Version:iOS 10.0 (14A5345a)
Classification:Performance / Something not on this list Reproducible:Always
 
Area:
Something not on this list

Summary:
In iOS 10, calling the property scheduledLocalNotifications on UIApplication can block the main thread for up to 10 seconds.

This happens after calling -[UIApplication scheduleLocalNotification:] or -[UIApplication cancelLocalNotification:] with notifications of repeatInterval set to NSCalendarUnitHour multiple times.

Steps to Reproduce:
1. Schedule 12 UILocalNotification with repeatInterval set to NSCalendarUnitHour using the method -[UIApplication scheduleLocalNotification:] for 6 times consecutively until maximum number of possible notifications have been set (64).

2. Cancel 12 scheduled UILocalNotification each time with -[UIApplication cancelLocalNotification:] for 6 times consecutively until all notifications have been cleared.

See sample code and video attached. Performance may sometimes be extremely sluggish to the point of unusable (up to 10s, as in the video), but other times just plain slow (around 1s).

Expected Results:
Calling UIApplication.scheduledLocalNotifications should return the results in under a second without blocking the main thread.

Actual Results:
Calling UIApplication.scheduledLocalNotifications begin to take longer and longer with each loop of scheduling.This can sometimes take up to 10s to access, blocking the main thread.

Version:
iOS 10.0 (14A5345a)

Notes:
1) Although iOS 10 introduce UserNotifications framework, unfortunately because of bug rdar://26855019, apps still need to use UILocalNotification to schedule notifications that repeat every hour.

2) Scheduling notifications with repeatInterval set to NSCalendarUnitMinute does not seem to suffer the same performance issue as those with repeatInterval set to NSCalendarUnitHour.

3) While calling setScheduledLocalNotifications: can address the performance issue somewhat, this is not always possible if the app would like to cancel a specific notification (while the app is backgrounded) without also dismissing other notifications that have already been presented.

Configuration:
iPhone 6s Plus

Attachments:
'SlowNotifications.mp4' and 'Slow Notifications.zip' were successfully uploaded.

https://www.dropbox.com/s/qolfsgt0jzl8ksn/Slow%20Notifications.zip?dl=1
https://www.dropbox.com/s/zoqmyvat54b5tx8/SlowNotifications.mp4?dl=1

Comments


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!