I believe you must set your applications background modes to allow location updates. To do this edit your apps .plist file and add "location" as a "Required background mode" see the Apple docs for more background modes (here)
iOS7.1 LocationManager pausing when entering background (works in 7.0)
-
12-07-2023 - |
سؤال
Slightly confused on this one so I broke it down to a test app.
Simple singleton handling locationManager. I have turned on location support in the background under capabilities. Map is also enabled.
The location manager is running all the time but as soon as I put the application in to the background, it pauses.
I have read many posts about people trying to start location manager in the background, but mine is already running. I assumed by enabling it under capabilities, it would continue to run in the background. As soon as the app resumes, so does location manager.
Do I need to start looking in to beginBackgroundTaskWithExpirationHandler?
UPDATE
The code works in 7.06 and not 7.1.1? what did they change?
المحلول
نصائح أخرى
in appDelegete.m
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[locationmanger startUpdatingLocation];//start your location update method here
//then add this code
backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[self endBackgroundTask];
}];
}
-(void) endBackgroundTask
{
[[UIApplication sharedApplication] endBackgroundTask:backgroundTask];
backgroundTask = UIBackgroundTaskInvalid;
}
it will work now