jodm
jodm

Reputation: 2617

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

Upvotes: 0

Views: 1167

Answers (2)

rckoenes
rckoenes

Reputation: 69499

Read the Apple documentation on Location in background. Timmers can't be used in the background.

If you keep CLLocationManager running with the correct settings it will only call location update on major change, which is when the user moves between cell towers/wi-fi points.

Upvotes: 1

Abizern
Abizern

Reputation: 150755

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.

Upvotes: 2

Related Questions