Stop updating kernel locations and then restarting them with a timer

I was wondering if someone could point me to (or paste) some code to disable Core Location updates to save power.

As far as I understand, you should stop updating the Core Location as soon as you get the required precision. If after a certain amount of time you don't get a good reading of the accuracy, you should also stop the updates (presumably using a timer) Every time you stop updates, you must start a timer (about 60 seconds) to restart Core Location and get a new reading.

Is there any Apple code that does all of this? The LocateMe, TaggedLocations and Locations example code doesn't seem to do this.

+2


a source to share


1 answer


The LocateMe example has the code you need. You just need to create a second selector for fire. LocateMe calls the install method in it ...

    [self performSelector:@selector(stopUpdatingLocation:) withObject:@"Timed Out" afterDelay:[[setupInfo objectForKey:kSetupInfoKeyTimeout] doubleValue]];

      

It says that after a while (kSetupInfoKeyTimeout) call the method stopUpdatingLocation

with the NSString = "Timed Out" argument. Internally, the method stopUpdatingLocation

[locationManager stopUpdatingLocation]

is called to stop stopping CoreLocation.



So, all you have to do is add another selector like this ...

[self performSelector:@selector(timeToRestartCoreLocation) afterDelay: 60];

      

inside a method stopUpdatingLocation

that will call the method timeToRestartCoreLocation

after 60 seconds. Then, in your method, timeToRestartCoreLocation

call [locationManager startUpdatingLocation]

to run CoreLocation again.

+3


a source







All Articles