LocationManager gocha!

Oh boy, what a mess this caused me.  I am currently working on a project that uses the location manager a lot and needs to keep track of the person location even running in the background. In testing, everything was working except background running.  I searched and tried everything, it seemed to work on a device running 7.06, but not in 7.1.1.  Instantly I thought BUG.  Sadly it was my stupidity!

To save battery life, at the weekend I turned off Background App Refresh but had completely forgotten about it.  I had also not implemented the tests to see if this was enabled in my code.  Background App Refresh disables location services running in the background!

I now use the following code to check for this.

 

– (void)checkForIssues
{
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
{
if ([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusAvailable)
{
NSLog(@”All good”);
}
else if([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusDenied)
{
NSLog(@”Error disabled”);
}
else if([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusRestricted)
{
NSLog(@”Error disabled”);
}
}
}

Leave a Reply