Reputation: 13
I have a GPS logging feature in my application. There are a couple options to be configured for this feature in my apps "Settings page". However, this feature depends on location services being enabled (on the actual iPhone itself). So for the configurable options, I have it check locationServicesEnabled(), and if false, disable the ability to set the options.
However, seeing the text below the options I added, "Location services need to be enabled", the user will click the Home button most likely, go to iPhone settings, enable location services, then go back to the app to configure the settings. However, since I have the enabled/disabled options changing in viewDidAppear(), they have to leave the current view and go back for the options to be enabled.
So (in Swift preferably), is there an easy way to listen for a change on the locationServicesEnabled(), and if so, execute a function, which in this case would be re-enabling the configurable options in my app. Thanks!
EDIT: So it looks like I might be able to use the delegate method for CLLocationManagerDelegate, didChangeAuthorizationStatus. Would this be the correct way to go about this?
Upvotes: 0
Views: 706
Reputation: 131418
You should create an instance of the location manager and set yourself up as it's delegate.
You should then implement the didChangeAuthorizationStatus
delegate method. It will be called if the user authorizes your app for location services.
You can either create an instance of the location manger in each view controller that needs to know about this change, or create your own class that manages an instance of the location manager (a "Location Manager Manager", if you will). I'd make that class a singleton. Then you can have it broadcast a custom notification when the location manager changes.
I would recommend creating a singleton that holds and manages a single instance of the location manager. That's what I usually do.
Upvotes: 2