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