Search code examples
iphoneobjective-ciosgeolocationcllocationmanager

Many CLLocationManager instance


If I init additional CLLocaitonManager instance that track user location, is It will increase the load? Or Should I using one CLLocaitonManager instance between classes?


Solution

  • Creating too many CLLocationManager or increasing the update intervals of the Core location services severely drains battery. So creating too many instances is not advised. Dont see a need for this.

    A good practice is to init one CLLocationManager in a viewController. If moving to another viewController, then stopUpdates on the current CLLocationManager & create a new manager in the new viewController. This is one pattern.

    Another pattern is to create a CLLocationManager in app delegate & make it available throughout your app. This is like a global variable. But generally avoid global declaration of this variable because it continuously consumes your battery life.

    So basically if all your classes are part of only one viewController then create only one CLLocationManager & share the location updates. If not then create one for each viewController.