My application needs to track user location changes in the background and works fine as long as user moves around.
When user stops and CLLocationManager
pauses after 10-20 minutes or so. It is indicated by this notification:
-(void)locationManagerDidPauseLocationUpdates:(CLLocationManager *)manager{}
And this is also fine with me. Great, I save some battery, etc.
The problem is that CLLocationManager
never wakes up when user starts moving again and following delegate methods are never fired until I put my application to the foreground (gets active):
//Never called back after CLLocationManager pauses:
-(void)locationManagerDidResumeLocationUpdates:(CLLocationManager *)manager{}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{}
Why is locationManagerDidResumeLocationUpdates
never called after device starts moving again? Shouldn't GPS resume automatically also (since was paused automatically)?
Is there a way to resume GPS without user's interaction?
Application has following declared in Info.plist file:
And my CLLocationManager settings are:
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager setActivityType:CLActivityTypeFitness];
//I WANT pauses to save some battery, etc... That is why following line is commented out (default)
//[locationManager setPausesLocationUpdatesAutomatically:NO];
locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…