我正在尝试在应用关闭时更新应用的徽章数量,任何人都可以告诉我们,如果应用关闭,我们可以更新吗?我使用以下代码:
NSCalendar *gregCalendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *dateComponent = [gregCalendar components:NSCalendarUnitYear | NSCalendarUnitWeekOfYear fromDate:[NSDate date]];
NSDateFormatter *outputFormatterHour = [[NSDateFormatter alloc] init];
[outputFormatterHour setDateFormat:@"HH"];
NSDateFormatter *outputFormatterMin = [[NSDateFormatter alloc] init];
[outputFormatterMin setDateFormat:@"mm"];
int hour = [[outputFormatterHour stringFromDate:_selectTimePicker.date] intValue];
int min = [[outputFormatterMin stringFromDate:_selectTimePicker.date] intValue];
[dateComponent setHour:hour];
[dateComponent setMinute:min];
NSDate *fireDate = [gregCalendar dateFromComponents:dateComponent];
UILocalNotification *localNotification = [[UILocalNotification alloc]init];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
[localNotification setAlertTitle:@"Notification"];
[localNotification setAlertBody:@"Body" ];
[localNotification setAlertAction:@"Open App"];
[localNotification setHasAction:YES];
[localNotification setAlertLaunchImage:@"AppIcon"];
localNotification.applicationIconBadgeNumber++;
[localNotification setFireDate:fireDate];
localNotification.repeatInterval = NSCalendarUnitDay;
[localNotification setTimeZone:[NSTimeZone defaultTimeZone]];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];