Search code examples
iosuiviewcontrollerlocationcllocationmanagercllocation

How to create a single instance of CLLocationManager in application?


I am currently developing an iOS application using the iOS 8 SDK and Xcode 6.

My app is created using storyboards and IB. In one of the view controllers, I have an instance of CLLocationManager running that monitors the user's location in the standard way. I want to be able to use this single location manager in other view controllers as well. Is there a way to do this?

Thanks, Siddharth


Solution

  • If I understand this correctly you want to let other parts of your application knows about location updates. If that is the case you can create a CLLocationManager in your AppDelegate class and use AppDelegate as its delegate. Whenever a new location update occurs you can use NSNotificationCenter to deliver this location update to other parts of the app.