Mac CoreLocation Services does not ask for permissions

Posted by Ryan Nichols on Stack Overflow See other posts from Stack Overflow or by Ryan Nichols
Published on 2012-06-29T00:13:35Z Indexed on 2012/07/08 21:16 UTC
Read the original article Hit count: 306

Filed under:
|
|

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];

UPDATE: Answer

It seems there is a problem with Sandboxing in which the CoreLocation framework is not allowed to talk to com.apple.CoreLocation.agent. I suspect this agent is responsible for prompting the user for permissions.

If you add the Location Services Entitlement (com.apple.security.personal-information.location) it only gives your app the ability to use the CL framework. However you also need access to the CoreLocation agent to ask the user for permissions. You can give your app access by adding the entitlement 'com.apple.security.temporary-exception.mach-lookup.global-name' with a value of 'com.apple.CoreLocation.agent'. Users will be prompted for access automatically like you would expect. I've filed a bug to apple on this already.

© Stack Overflow or respective owner

Related posts about osx

Related posts about cocoa