Outdooractive / route-me

Open source map library for iOS
Other
122 stars 400 forks source link

Fix CLLocationManager management #106

Open noberasco opened 11 years ago

noberasco commented 11 years ago

Hi,

there is a bug in Alpstein/route-me management of CLLocationManager.

Basically, if userTrackingMode is set to either RMUserTrackingModeFollow or RMUserTrackingModeFollowWithHeading, a CLLocationManager is instantiated to keep track of location changes.

So far so good.

However, if application is registered to get location updates in background, when application enters background mode, this location manager does not get deactivated, meaning that the GPS receives is kept active, draining the battery needlessly.

I'll explain better with an example. I have an application (EasyTrails, basically a GPS tracker) that is registered to receive location updates in background. However, I keep the location manager active in background only while the user is actually recording a track, otherwise the application will be sent to background just like any other application. Your use of CLLocationManager disrupts this behavior, since your instance of CLLocationManager does not get deactivated when application goes into background.

This pull request does just that: it registers with UIApplication status updates so that it can disable, if needed, the location manager when entering background mode and reenable it when application returns to foreground.