Reputation: 1918
How can I monitor when [CLLocationManager locationServicesEnabled]
changed? I need something like delegate
or notification
.
Upvotes: 3
Views: 958
Reputation: 39
As iOS doesn't have a native callback/notification when user change global location service settings, we cannot handle it directly. But you can club
[CLLocationManager locationServicesEnabled]
with
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
//Check new status
}
to achieve the desired effect like:
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
if (![ CLLocationManager locationServicesEnabled]) {
//perform action when location service is disabled
}
}
Although do understand that if the permission is already denied and the location settings are changed, you wont get this callback.
Upvotes: 2
Reputation: 4671
Use delagte method of CLLocationManager
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
These are the CLAuthorizationStatus description in documentation:
> typedef enum {
> kCLAuthorizationStatusNotDetermined = 0, // User has not yet made a choice with regards to this application
> kCLAuthorizationStatusRestricted, // This application is not authorized to use location services. Due
> // to active restrictions on location services, the user cannot change
> // this status, and may not have personally denied authorization
> kCLAuthorizationStatusDenied, // User has explicitly denied authorization for this application, or
> // location services are disabled in Settings
> kCLAuthorizationStatusAuthorized // User has authorized this application to use location services
} CLAuthorizationStatus;
Upvotes: 5
Reputation: 107131
You can do it using the locationManager:didChangeAuthorizationStatus: method:
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
//Check new status
}
Upvotes: 2