I'm writing this iOS app that contains geo tracking functionality. In my .plist, I have put
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
too make sure the app is not suspended in the background.
The crucial GPS code is in my appDelegate, and looks like this:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
BOOL isInBackground = NO;
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
isInBackground = YES;
}
if (isInBackground) {
[self sendBackgroundLocationToServer:[locations lastObject]];
} else {
// If we're not in the background wait till the GPS is accurate to send it to the server
if ([[locations lastObject] horizontalAccuracy] < 100.0f) {
[self sendDataToServer:[locations lastObject]];
}
}
}
However, my app stops recording fresh locations to my server after having been in the background for a while.
What could be the cause, and how do I solve this?
Thanks for your advice