0
我在的.plist添加了所有3個可能的密鑰獲取背景位置更新:無法在iOS版11
隱私 - 位置始終和使用時使用情況說明
隱私 - 位置在使用時的用法說明
隱私 - 位置用法說明
我的代碼是:
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)")
}
當在前臺應用程序中,我可以看到位置更新,但當我按Home鍵時 - 位置更新停止。 我做錯了什麼?
的Xcode 9.0版(9A235) 的iOS 11.0.2
allowedBackgroundLocationUpdates - 我錯過了 – daleijn