UserNotifications.Framework does not schedule local notifications that set badge value to 0

Originator:jeff
Number:rdar://29859960 Date Originated:2017-01-03
Status:Open Resolved:
Product:iOS + SDK Product Version:10.2 (14C92)
Classification: Reproducible:Always
 
Area:
UserNotifications Framework

Summary:
When scheduling a local notification with content with a badge value of 0 and no other attributes, the notification will never post. Creating the exact same notification with a non-zero value does successfully update the badge. Scheduling the notification with a 0 value fails to clear the badge.

Steps to Reproduce:
1. Set the application badge to a non-zero value: UIApplication.shared.applicationIconBadgeNumber = 2
2. Create a local notification with an instance of: let content = UNMutableNotificationContent()
3. Set: content.badge = NSNumber(value: 0)
4. Create a notification trigger sometime in the future: let notificationBadgeZeroTrigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 5, repeats: false)
5. Create the notification request: let notificationBadgeZeroRequest = UNNotificationRequest.init(identifier: "0", content: content, trigger: notificationBadgeZeroTrigger)
6. Add the notification request to the notification center: UNUserNotificationCenter.current().add(notificationBadgeZeroRequest)

Expected Results:
When the notification trigger fires (5 seconds in the above example), the application badge should be set to 0 (cleared).

Actual Results:
Nothing. The notification is never listed in either the pending or delivered notification arrays (UNUserNotificationCenter.current().getDeliveredNotifications() or UNUserNotificationCenter.current().getPendingNotifications()).

Version:
10.2 (14C92)

Notes:
I’ve attached an example project that demonstrates this behavior. When the ‘Start’ button is pressed, the application badge is set to 0. Then press the Home button to send the app to the background. Every five seconds, the badge value should increment: 1, 2, 3, 4. The next notification after 4 should set the badge to 0. The badge value is never cleared.

As a workaround to this, adding a title string to notification content does result in the posting of this notification. But having an NSNumber value of 0 behave differently (and in an undocumented fashion) from non-zero values seems to be a bug.

Configuration:
Occurs on all configurations of 10.2 that I've tested (iPad, iPhone, Simulator).

Attachments:
https://jeffvautin.com/wp-content/uploads/openradar/radar29859960UserNotificationZeroBadgeTest.zip
https://jeffvautin.com/wp-content/uploads/openradar/radar29859960UserNotificationZeroBadgeTestSwift5.zip

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!