I am trying to implement pending location updates in order to have better battery consumption. I start my location manager as follows:
- (void)initCoreLocation
{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.pausesLocationUpdatesAutomatically = YES;
self.locationManager.activityType = CLActivityTypeAutomotiveNavigation;
if ([self.locationManager respondsToSelector:@selector(allowsBackgroundLocationUpdates)]) {
self.locationManager.allowsBackgroundLocationUpdates=YES;
}
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
}
[self.locationManager startUpdatingLocation];
[self.locationManager startMonitoringSignificantLocationChanges];
}
And starting a delayed update, for example, as follows:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
if (!self.deferringUpdates) {
[self.locationManager allowDeferredLocationUpdatesUntilTraveled:CLLocationDistanceMax timeout:30];
self.deferringUpdates = YES;
}
}
-(void)locationManager:(CLLocationManager *)manager didFinishDeferredUpdatesWithError:(NSError *)error {
if(error) {
NSLog(@"error");
}
NSLog(@"didFinishDeferredUpdates");
self.deferringUpdates = NO;
}
I have a didFinishDeferredUpdateslog every 30 seconds, however it didUpdateLocationskeeps ringing every second, removing any attempt to optimize battery consumption. Is the location manager supposed to call didUpdateLocationsevery 30 seconds?
source
share