【发布时间】:2016-02-01 20:14:30
【问题描述】:
以下代码有问题。我的目标是在指定时间清除应用的徽章计数:
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];
第一个徽章设置良好,但 30 秒后,当第二个徽章要触发时,徽章编号保持在 5。有趣的是,如果我将 secondBadgeNumber 设置为 0 以外的任何 int,徽章编号就会更新。
我在 iOS 9.0.2 和 iOS 9.1 上看到了这些症状。在 iOS 7 和 8 上,将徽章编号设置为 0 即可很好地清除徽章。
对于 iOS 9 的变通方法有什么建议吗?
干杯!
【问题讨论】: