iOS - 本地通知不更新徽章编号

时间:2016-04-05 06:57:25

标签: ios objective-c iphone notifications uilocalnotification

我正在尝试更新本地通知徽章计数,但它始终显示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];

0 个答案:

没有答案
相关问题