Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use CLLocationManager in an OS X Today Extension?

I'm trying to get the user's location in a Today Extension and I'm hitting a dead end.

On an OS X app, when you call locationManager.startUpdatingLocation(), a dialog pops up asking if you want to let the app use your location. In the Today view, though, nothing comes up at all after calling this method, and my delegate doesn't get called for didUpdateLocations or for didFailWithError. CLLocationManager.authorizationStatus() returns NotDetermined. I have been looking at Apple's docs on Today Extensions and am not seeing much about permissions or about getting the user's location.

How are we intended to get the user's location in an OS X Today Extension?

Edit: One thing to note is that CLLocationManager.locationServicesEnabled() returns true on my OS X app and false on my Today Extension. What does this mean, and how can I change this?

like image 485
Rikki Gibson Avatar asked Jun 12 '16 18:06

Rikki Gibson


1 Answers

OS X Today Extensions use an App Sandbox by default and you need to check the right boxes to allow the Today Extension to do things like get the user's location and make network calls.

Go to your project settings in Xcode, select your OS X Today Extension target, click the Capabilities tab, expand the App Sandbox section, and check the boxes for the capabilities you want (in my case, Location and Outgoing Network Connections).

like image 85
Rikki Gibson Avatar answered Sep 27 '22 20:09

Rikki Gibson