我正在尝试更新本地通知徽章计数,但它始终显示1.徽章计数不一致。我使用以下代码:
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:@"Title"];
[localNotification setAlertBody:@"Body" ];
[localNotification setAlertAction:@"Open App"];
[localNotification setHasAction:YES];
[localNotification setAlertLaunchImage:@"AppIcon"];
[localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber] + 1];
//localNotification.soundName = @"beep.wav";
[localNotification setFireDate:fireDate];
localNotification.repeatInterval = NSCalendarUnitDay;
[localNotification setTimeZone:[NSTimeZone defaultTimeZone]];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];