Updating app via App Store fails to cancel old repeating UILocalNotifications

Originator:jaredsinclair.rn
Number:rdar://12072780 Date Originated:August 9, 2012
Status:Open Resolved:
Product:iPhone SDK Product Version:5.x
Classification:Serious Bug Reproducible:Rarely
 
Quick Summary:
-------------

Calling cancelAllLocalNotifications sometimes fails to cancel repeating notifications created with Version N of an app after updating to Version N+1 via the App Store.
 

Summary:
--------
I'm the developer of Pillboxie (www.pillboxie.com), a medication reminder app for iOS. My app uses UILocalNotifications to remind users to take medications. Some users opt for repeating reminders, which take advantage of the UILocalNotification property called "repeatInterval"  by setting it to NSMinuteCalendarUnit. These notifications fire once a minute, every minute, until the user launches Pillboxie and marks them complete.

Since the introduction of iOS 5 last year, apps that use UILocalNotification with a repeatInterval of NSMinuteCalendarUnit have encountered an uncommon but serious bug: when some users update their apps via the App Store's standard updating process, old UILocalNotifications with an NSMinuteCalendarUnit repeatInterval cannot be cancelled. Instead, as soon as the app is updated, these reminders begin to fire every minute. 

Furthermore, calling "cancelAllLocalNotifications" on the UIApplication singleton instance *silently* fails. The method executes without error. As far as my code is aware, all the notifications were cancelled. Querying the application singleton for its scheduledLocalNotifications array returns no notifications. Yet, the old notifications continue to repeat indefinitely, until the user either deletes the app or power cycles the device.


Steps to Reproduce:
-----------------
This bug is extremely rare, however the majority of app updates since the introduction of iOS 5 has been associated with at least a dozen reports from my customers of this issue.

In my personal testing, I have been unable to replicate the bug on my test devices. This is partly because of the fact that it is the *app update process itself* that is a key step in the road to the bug. To the best of my knowledge, these are the factors that lead to a high probability that the bug will surface:

1. Release Version N of an app via the App Store that uses UILocalNotifications with a repeatInterval of NSMinuteCalendarUnit.

2. Schedule some of these notifications with the app, Pick a fire date a few minutes in the future.

3. The notifications will fire at the scheduled date/time. Launch the app when they fire.

4. After the app launches (either in didBecomeActive or didFinishLaunching), automatically call cancelAllLocalNotifications.

5. After canceling all the notifications, create some new UILocalNotifications, again with fireDates a few minutes in the future, and repeatIntervals of NSMinuteCalendarUnit.

6. Repeat steps 2 through 5 ad lib. 

7. Release Version N+1 of the app via the App Store, changing nothing relevant to the UILocalNotification code.

8. Update the app via the App Store, then launch the app and repeat steps 4 and 5.

9. When this latest round of UILocalNotifications fire, launch the app. You will try to repeat Step 4, and it will appear to work (and indeed, 99% percent of the time it does).

10. The other 1% of the time, the following occurs: "cancelAllLocalNotification" silently fails. No errors are generated, but the old notifications were not properly cancelled.

11. You can query the UIApplication shared instance for its scheduledLocalNotifications array, but it will return no notifications (as you would expect).

12. Exiting the app, however, leads to a very distressing situation: the UILocalNotifications that failed to get cancelled properly will begin to fire every minute, endlessly.

13. Repeat Step 4 until you tire of doing so. Every time you exit the app, the UILocalNotifications continue to repeat as they do in Step 12.


Expected Results:
---------------

Calling cancelAllLocalNotifications should always cancel all local notifications.


Actual Results:
------------

Calling cancelAllLocalNotifications fails to cancel notifications created with Version N-1 of an app.


Regression:
----------

The only fix that I've found for customers who experience this issue is to power cycle the device. Somehow, power cycling the device will cancel the rogue notifications. All other methods of canceling reminders fail (except, of course, for deleting the app, which is unacceptable).


Notes:
-------

This bug is related to this radar from the developer of Due, another high-quality app using UILocalNotification: LINK: http://openradar.appspot.com/radar?id=1846406.

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!