ARTICLES
CLLocationManager and tvOS
How to access the user’s location with CLLocationManager on tvOS.
- Add the key
NSLocationWhenInUseUsageDescription
to your Info.plist. Also add a default value that will be displayed in the prompt to the user. - Add the key
CFBundleDisplayName
to your Info.plist. Also add a default value that will be displayed as the App name in the home screen and in the prompt. - Localize your prompt and display name by adding a InfoPlist.strings file. This file can be located in the same directory as your Localizable.strings file.
- Add
NSLocationWhenInUseUsageDescription
andCFBundleDisplayName
as keys and localize their values.
- Add
According to Apple you should create a strong reference to CLAuthorizationStatus
and implement the CLLocationManagerDelegate
. Below is some sample code:
let authorizationStatus: CLAuthorizationStatus = CLLocationManager.authorizationStatus()
if (authorizationStatus == CLAuthorizationStatus.Restricted || authorizationStatus == CLAuthorizationStatus.Denied) {
self.locationManager = nil
} else {
self.locationManager = CLLocationManager()
}
if (self.locationManager != nil) {
self.locationManager!.delegate = self
//Request Permission to Use Location Services
if (authorizationStatus == CLAuthorizationStatus.NotDetermined) {
self.locationManager!.requestWhenInUseAuthorization()
}
self.locationManager!.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager!.requestLocation()
}
Documentation:
Did you find this post helpful? Support independent development and improve your sleep by downloading White Noise and Deep Sleep Sounds free from the App Store.
Tested with:
Xcode Version 7.2.1
tvOS 9.1.1
Swift 2.1.1
Our Products
Kitemetrics
Keyword level attribution for Apple Search Ads. Optimize your bids and increase your revenue. Sign up for free at kitemetrics.com.
White Noise and Deep Sleep Sounds
Calming and relaxing sounds that will help you sleep like a baby tonight.
Download for free from the App Store.
Get it on Google Play.
Our Sponsors
Get Sleepy
The free podcast that puts you to sleep with meditative bedtime stories. Listen at getsleepy.com.