I have a problem keeping the GPS running in background.
I succeded to keep the GPS running when the app is in background, but it stops sometimes. I noticed that it stops when i enter in a building and i stay there for 2-3 hours. "Stops" means that i don't receive any GPS point even though the location service icon is still on. Then when i get out i don't receive any points until I bring my application to foreground.
I set the pausesLocationUpdatesAutomatically property to NO.
So, everything works fine until i get into a location with weak gps signal. When i get out of that area i don't receive points anymore, even though I should because the gps signal is now good.
And here is my code when the applications enters in background:
- (void)applicationWillResignActive:(UIApplication *)application
{
NSLog(@"[AppDelegate]: Application entering in background!");
if(doesUserWantGPSTracking)
{
[self stopGPS];
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:
^{
dispatch_async(dispatch_get_main_queue(),
^{
if( bgTask != UIBackgroundTaskInvalid )
{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}
});
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^{
[self startGPS];
dispatch_async(dispatch_get_main_queue(), ^{
if( bgTask != UIBackgroundTaskInvalid )
{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}
});
});
}
}