Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac CoreLocation Services does not ask for permissions

I'm writing a Mac App that needs to use CoreLocation services. The code and location works fine, as long as I manually authenticate the service inside the security preference pane. However the framework is not automatically popping up with a permission dialog. The documentation states:

Important The user has the option of denying an application’s access to the location service data. During its initial uses by an application, the Core Location framework prompts the user to confirm that using the location service is acceptable. If the user denies the request, the CLLocationManager object reports an appropriate error to its delegate during future requests.

I do get an error to my delegate, and the value of +locationServicesEnabled is correct on CLLocationManager. The only part missing is the prompt to the user about permissions. This occurs on my development MPB and a friends MBP. Neither of us can figure out whats wrong.

Has anyone run into this?

Relevant code:

_locationManager = [CLLocationManager new];    
[_locationManager setDelegate:self];
[_locationManager setDesiredAccuracy:kCLLocationAccuracyKilometer];
...
[_locationManager startUpdatingLocation];
like image 607
Ryan Nichols Avatar asked Jun 29 '12 00:06

Ryan Nichols


1 Answers

I found that on the Mac, that when you start location services by calling

[locationManager startUpdatingLocation];

It triggers

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

With a status of

kCLAuthorizationStatusNotDetermined

If you watch for this status, then start updating the location again, it triggers the permission dialog: e.g.

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
    switch (status) {
        case kCLAuthorizationStatusAuthorized:
            NSLog(@"Location Services are now Authorised");
            [_locationManager startUpdatingLocation];

            break;

        case kCLAuthorizationStatusDenied:
            NSLog(@"Location Services are now Denied");
            break;

        case kCLAuthorizationStatusNotDetermined:
            NSLog(@"Location Services are now Not Determined");

            //  We need to triger the OS to ask the user for permission.
            [_locationManager startUpdatingLocation];
            [_locationManager stopUpdatingLocation];

            break;

        case kCLAuthorizationStatusRestricted:
            NSLog(@"Location Services are now Restricted");
            break;

        default:
            break;
    }
}
like image 130
Diggory Avatar answered Oct 21 '22 19:10

Diggory