Update location on background mode do not work when user turn off "Background App Refresh"

StackOverflow https://stackoverflow.com/questions/22832877

  •  26-06-2023
  •  | 
  •  

Question

I want to notify for user to turn on "Background App Refresh" to update location on background mode. How can I check status of this feature on my code?

Était-ce utile?

La solution

Method 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.");
}

Method 2

NSArray *backgroundRefreshAuthStatuses = @[@"Restricted",@"Denied",@"Available"];
int brAuth = (int)[[UIApplication sharedApplication] backgroundRefreshStatus];
NSLog(@"Background refresh authorization status: %@", [backgroundRefreshAuthStatuses objectAtIndex:brAuth]);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top