【发布时间】:2015-11-16 15:20:45
【问题描述】:
让 tvOS 提示用户进行位置数据授权似乎有点麻烦。我从字面上复制并粘贴了 iOS 的工作代码,它似乎没有提示用户。我正在使用下面列出的代码以及带有字符串值的 NSLocationWhenInUseUsageDescription 键。我看到的 api 的唯一区别是在 iOS 上它使用 startupdatinglocation() 而在 tvOS 上它使用 requestLocation()(类似于 watchOS)我已经解决了这个问题,它实际上是在点击 requestWhenInUseAuthorization() 但根本没有提示用户。
知道发生了什么吗?
import UIKit
import CoreLocation
class ViewController: UIViewController {
var locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
if CLLocationManager.locationServicesEnabled(){
if CLLocationManager.authorizationStatus() == CLAuthorizationStatus.NotDetermined{
locationManager.requestWhenInUseAuthorization()
}
else if CLLocationManager.authorizationStatus() == CLAuthorizationStatus.AuthorizedWhenInUse{
locationManager.requestLocation()
}
}
}
【问题讨论】:
标签: swift cllocationmanager tvos