Reputation: 887
I'm having a problem with the following code. My goal here is to clear an app's badge count at a specified time:
NSInteger firstBadgeNumber = 5;
NSInteger secondBadgeNumber = 0;
UILocalNotification *firstNotification = [[UILocalNotification alloc] init];
firstNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow: 1];
firstNotification.timeZone = [NSTimeZone defaultTimeZone];
firstNotification.applicationIconBadgeNumber = firstBadgeNumber;
[[UIApplication sharedApplication] scheduleLocalNotification:firstNotification];
UILocalNotification *secondNotification = [[UILocalNotification alloc] init];
secondNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow: 31];
secondNotification.timeZone = [NSTimeZone defaultTimeZone];
secondNotification.applicationIconBadgeNumber = secondBadgeNumber;
[[UIApplication sharedApplication] scheduleLocalNotification:secondNotification];
The first badge sets fine, but 30 seconds later, when the second badge is meant to fire, the badge number stays at 5. Interestingly, if I set secondBadgeNumber to any int other than 0, the badge number updates.
I'm seeing these symptoms on iOS 9.0.2, and iOS 9.1. On both iOS 7 & 8 setting the badge number to 0 clears the badge just fine.
Any suggestions on a work around for iOS 9?
Cheers!
Upvotes: 1
Views: 125
Reputation: 3956
Even i faced the same problem, setting it to 0 doesn't remove the app badge as 0 stands for default or no change. Instead you can try setting it to negative number. Try
secondNotification.applicationIconBadgeNumber = -1;
This should work. Hope it helps!
Upvotes: 2