Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C - CLLocationManager find out when "Allow" or "Don't allow" is clicked

When doing CLLocationManager, is there a delegate method that gets called when a user clicked the "Allow" or "Don't allow" prompt that request to use Location?

I tried this but this doesn't get called after a user "Allow" or "Don't allow".

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status;

Also, is there a variable that will tell me what the user selected?

I tried the below, but that always returns true.

locationManager.locationServicesEnabled

Thank you,
Tee

like image 350
teepusink Avatar asked Dec 17 '22 08:12

teepusink


2 Answers

There is a delegate method for that

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
    if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized) {
        // user allowed
    }

}
like image 182
Peter Lapisu Avatar answered Feb 15 '23 09:02

Peter Lapisu


[CLLocationManager locationServicesEnabled] only tells your if the location service are enabled on the device.

[CLLocationManager authorizationStatus] returns the actual status you're looking for.

like image 36
Pierre Avatar answered Feb 15 '23 09:02

Pierre