1

I am trying to use this technique in iOS7 to get a location every x seconds - Periodic iOS background location updates.

In my didUpdateLocations:

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    [self.locationManager setDesiredAccuracy:kCLLocationAccuracyKilometer];
    [self.locationManager setDistanceFilter:9999];
}

When i run this, i seem to get a loop. setDesiredAccuracy: - i think this forces an update itself, on change. This is why I am getting a loop, would this be right? When I comment these out, it acts like I expect it too. Is there anyway to stop it get location when i set these?

Community
  • 1
  • 1
rjg
  • 105
  • 1
  • 12
  • The approach you are taking is wrong due to some changes in multitasking in iOS 7 This approach will not work as you are expecting : 1) Increasing the value of distanceFilter property doesn't result in battery saving because gps still has to keep figuring your location. 2) In iOS 7 background time is non - contiguous. 3) You might take into account significantChangeLocation services. 4) Apart from your soution in iOS 7 you can't start UIBackgroundModes - location from background – aMother Nov 03 '13 at 16:48

1 Answers1

0

Sounds like you should set some kind of time/date stamp on how often you call "setDesiredAccuracy". If you call it once, don't call it again for some certain period of time.

something like:

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    NSTimeInterval secondsSinceLastResetOfAccuracy = [lastResetTime timeIntervalSinceNow];
    if(secondsSinceLastResetOfAccuracy > 60 * 60) // one hour
    {    
        [self.locationManager setDesiredAccuracy:kCLLocationAccuracyKilometer];
        [self.locationManager setDistanceFilter:9999];
        lastResetTime = [NSDate date]; // new "time stamp"
    }
}
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • inside the if condition you need to place `secondsSinceLastResetOfAccuracy * -1` I suppose as `secondsSinceLastResetOfAccuracy ` will be a minus value according to this scenario and if condition will never met if we don't multiply it by `-1`. I mean when the variable `lastResetTime` is from the past `timeIntervalSinceNow` will return seconds in minus value. – Jay Mayu Feb 11 '15 at 04:10