【发布时间】:2017-10-11 19:31:41
【问题描述】:
我在 .plist 中添加了所有 3 个可能的键:
隐私 - 始终定位和使用时使用说明
隐私 - 使用时的位置使用说明
隐私 - 位置使用说明
我的代码是:
private lazy var locationManager: CLLocationManager = {
let manager = CLLocationManager()
manager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
manager.delegate = self
manager.requestAlwaysAuthorization()
return manager
}()
@IBAction func enabledLocationUpdate(_ sender: UISwitch) {
if sender.isOn {
locationManager.startUpdatingLocation()
} else {
locationManager.stopUpdatingLocation()
}
}
extension LocationViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let mostRecentLocation = locations.last else {
return
}
NSLog("New location is \(mostRecentLocation)")
}
当应用程序在前台时,我可以看到位置更新,但是当我按下主页按钮时 - 位置更新停止。 我做错了什么?
Xcode 版本 9.0 (9A235) iOS 11.0.2
【问题讨论】:
标签: ios cllocationmanager ios11 xcode9 cllocation