Search code examples
iphonebackground-processcllocation

iPhone - Start / Stop CLLocationManager


This really leads off from my "brainstorm" last night here: iPhone Brainstorm - CLLocation in Background - Polling every 15 minutes

When my application is active I can stop the CLLocationManager after I get a correct reading. Then after the performSelector afterDelay I can start it again, take a reading and stop it.

If though the application is but to the background when I have a timer running it never restart the CLLocationManager. I have registered for background location updates and if I do not stop the CLLocationManager it is fine but for battery I was hoping I could keep start/stopping it.

Please advise.

Thanks James


Solution

  • Save the current time when the application enters the background.

    When it becomes active again:

    • If > 15 minutes has passed since the application entered the background - start CLLocationServices
    • If < 15 minutes has passed, start at timer with the remaining time until CLLocationServices needs to start.