Reputation: 5375
I'm currently using CLLocationManager
to always track geofences even when the application is in the background. I can't seem to find a way to listen for when location services is enabled/disabled.
Is it possible to listen for a location service enable/disable event or when location is enabled/disabled for your specific application while the application is closed?
Please note I'm using Xamarin, but Objective-C code is fine.
public class LocationManager
{
protected CLLocationManager locationManager;
public LocationManger()
{
this.locationManager = new CLLocationManger();
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
locationManager.RequestAlwaysAuthorization();
}
// ... get array of CLCircularRegion and start listening to each
// locationManager events...
locationManager.RegionEntered += (sender, e) => { /*stuff*/ };
locationManager.RegionLeft += (sender, e) => { /*stuff*/ };
locationManager.DidDetermineState += (sender, e) => { /*stuff*/ };
//locationaManager.SomeSortOfLocationServiceEnableDisableEvent += (sender, e) => { /*stuff*/ };
}
}
Upvotes: 2
Views: 1478
Reputation: 5858
A call to the class method [CLLocationManager locationServicesEnabled]
returns a BOOL
indicating whether location services are enabled or not.
If the user disables location services, locationManager:didChangeAuthorizationStatus:
will be called on a CLLocationManagerDelegate
.
Therefore, if you have a class conform to CLLocationManagerDelegate
and implement locationManager:didChangeAuthorizationStatus:
, you should be able to handle the disable event by the user.
Upvotes: 4