Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS-如果应用程序位于后台,是否可以更新本地通知的徽章计数?_Ios_Objective C_Iphone_Notifications_Uilocalnotification - Fatal编程技术网

iOS-如果应用程序位于后台,是否可以更新本地通知的徽章计数?

iOS-如果应用程序位于后台,是否可以更新本地通知的徽章计数?,ios,objective-c,iphone,notifications,uilocalnotification,Ios,Objective C,Iphone,Notifications,Uilocalnotification,我正在尝试在应用程序关闭时更新应用程序的徽章计数,有人能告诉我,如果应用程序关闭,我们可以更新它吗?我正在使用以下代码: NSCalendar *gregCalendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; NSDateComponents *dateComponent = [gregCalendar components:NSCalendarUnitYear |

我正在尝试在应用程序关闭时更新应用程序的徽章计数,有人能告诉我,如果应用程序关闭,我们可以更新它吗?我正在使用以下代码:

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];

到底是什么问题?如果显示通知,将设置徽章。选中此项当应用程序未运行时,唯一能够动态设置徽章编号的方法是使用推送通知。您必须在服务器端跟踪更新。另外,请查看第三条评论,我希望您能找到解决方案。让我们看看。问题到底是什么?如果显示通知,将设置徽章。选中此项当应用程序未运行时,唯一能够动态设置徽章编号的方法是使用推送通知。您必须在服务器端跟踪更新。另外,请查看第三条评论,我希望您能找到您的解决方案。