cancelAllLocalNotifications并不在当前消息循环立即生效,在iOS8 iphone5下的测试代码如下:
- (void)cancelLocalNotificationsAndClearBadge
{
UIApplication *app = [UIApplication sharedApplication];
app.applicationIconBadgeNumber = 0;
[app cancelAllLocalNotifications];
#ifdef DEBUG
NSLog(@"after cancelAllLocalNotifications:%@", app.scheduledLocalNotifications);
#endif
}
打印log表面数组中还是有值的。
而使用如下方法:
可以使得立即取值时,得到正确的空数组:
- (void)cancelLocalNotificationsAndClearBadge
{
UIApplication *app = [UIApplication sharedApplication];
app.applicationIconBadgeNumber = 0;
app.scheduledLocalNotifications = nil;
// [app cancelAllLocalNotifications];
#ifdef DEBUG
NSLog(@"after cancelAllLocalNotifications:%@", app.scheduledLocalNotifications);
#endif
}