I struggled a while yesterday with getting location services to work, and figured it out this morning.
tl;dr: From Settings app on TV:
Settings -> General -> Privacy -> Location Services -> Apps. Choose your app, and enable the needed location service level.
Here's what I had:
if status == CLAuthorizationStatus.NotDetermined {
print("requesting authorization")
locationManager.requestWhenInUseAuthorization()
}
// and then later...
locationManager.requestLocation()Info.plist had the correct NSLocationWhenInUseUsageDescription entry.
When I executed that code, and then queried CLAuthorizationStatus, the value came back as .NotDetermined. Repeatedly triggering the requestWhenInUseAuthorization() did nothing.
Calling .requestLocation() eventually triggered my CLLocationManagerDelegate's locationManagerDidFailWithError():
locationManager didFailWithError The operation couldn’t be completed. (kCLErrorDomain error 0.)I tried adding "location-services" to the "Required device capabilties". That generated "Can't install application: Mapbox Static TV.app cannot be installed on Apple TV. Mapbox Static TV.app requires the “location-services” capability which is not supported by Apple TV."
I finally went digging in the Settings menu, and saw my app listed there, with a blank authorization status. Siri was listed "while using the app", and Time Zone was listed "always". Choosing the app brought up an alert, to select "while using the app" or "never".
After I made that change in Settings, my first call to CLLocationManager.authorizationStatus() returned .AuthorizedWhenInUse, and my first call to .requestLocation() had the correct value in it.
Back to Settings. Set my app's permission to "never". Relaunch. Now I immediately see "denied" as status, and didFailWithError shows
locationManager didFailWithError The operation couldn’t be completed. (kCLErrorDomain error 1.)There's never a challenge generated by the system to choose location services permission, as you would see in iOS or OS X. Solution for the moment seems to be to query authorizationStatus(), and if it's showing .NotDetermined, put up your own instructions on what the user should do to authorize location services.
I'll update this with a Radar number once I file it.