我正在使用CLLocationManager
,查看CLLocationManager
属性并检查location
的location
(如果有)。该文档建议,如果无法确定level
,则只会返回level
。实际上,我得到的是floor
实例,但其floor
是2146959360。将其转换为十六进制的0x7FF80000,看起来可疑地像一些神秘的前哨值。
floor
我仅在物理iOS 13.3.1设备上看到此行为。 FWIW,较旧的iOS版本(我只在这里安装了iOS 10设备)看上去像模拟器一样返回nil
。
发生了什么事?
如果您呼叫CLFloor
,此问题将消失。如果这样做,则level
属性将为lazy var locationManager: CLLocationManager = {
let locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
return locationManager
}()
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
switch CLLocationManager.authorizationStatus() {
case .notDetermined: locationManager.requestWhenInUseAuthorization()
case .denied: redirectToSettings()
default: break
}
}
@IBAction func didTapGetLocation(_ sender: Any) {
updateLabels(for: locationManager.location)
}
func updateLabels(for location: CLLocation?) {
guard let location = location else {
floorLabel.text = "No location."
return
}
if let floor = location.floor {
let hexString = "0x" + String(format: "%08x", floor.level)
floorLabel.text = "\(floor.level) (\(hexString))"
} else {
floorLabel.text = "No floor."
}
}
。 nil
值为2146959360(0x7FF80000)的startUpdatingLocation
实例仅在您查询startUpdatingLocation
的floor
而没有首先调用floor
时出现。
文档建议此nil
属性使用最后一个已知值填充。无论如何,CLFloor
应该为level
(至少对于我的特定位置),但不是。 level
无效。
请参见location
,以举例说明错误的表现以及如何调用CLLocationManager
。
startUpdatingLocation
我已提交了错误报告(FB7638281)。