当用户关闭时,后台模式上的更新位置不起作用"后台应用程序刷新"

时间:2014-04-03 09:09:33

标签: ios xcode background refresh

我想通知用户打开“后台应用刷新”以更新后台模式的位置。如何在代码中检查此功能的状态?

1 个答案:

答案 0 :(得分:0)

方法1

if ([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusAvailable) {

    NSLog(@"Background updates are available for the app.");
}else if([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusDenied)
{
    NSLog(@"The user explicitly disabled background behavior for this app or for the whole system.");
}else if([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusRestricted)
{
    NSLog(@"Background updates are unavailable and the user cannot enable them again. For example, this status can occur when parental controls are in effect for the current user.");
}

方法2

NSArray *backgroundRefreshAuthStatuses = @[@"Restricted",@"Denied",@"Available"];
int brAuth = (int)[[UIApplication sharedApplication] backgroundRefreshStatus];
NSLog(@"Background refresh authorization status: %@", [backgroundRefreshAuthStatuses objectAtIndex:brAuth]);