最近,我在 Xcode 日志中收到了很多来自 CoreMotion 框架的奇怪警告,与函数 getLocationForBundleID
相关。 :
[Client] {"msg":"#NullIsland Either the latitude or longitude was exactly 0! That's highly unlikely", "latIsZero":0, "lonIsZero":0}
[Client] {"msg":"#NullIsland Received a latitude or longitude from getLocationForBundleID that was exactly zero", "latIsZero":0, "lonIsZero":0, "location":'28 5B E0 D7 EB 7F 00 00'}
我没有看到我的应用程序有任何故障。所以也许这些日志可以忽略不计,但无论如何它们都很烦人。我的问题是:
如何纠正潜在错误?
我怎样才能停止这些警告?
最佳答案
显然,如果属性 location
会记录此错误消息的 CLLocationManager
在 CLLocationManager
之前读取交付了第一个位置。
我的解决方案如下:
无论如何,我使用 CLLocationManager
的子类这允许我设置 location
以编程方式进行测试的属性。
这是按如下方式完成的:
private var _location: CLLocation?
@objc dynamic override var location: CLLocation? {
get {
let usedLocation = _location ?? super.location // Here the error is logged if no location has been delivered yet
return usedLocation
}
set {
_location = newValue
}
}
这个子类现在有一个额外的属性 var anyLocationDelivered = false
设置true
在 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
locationManager.anyLocationDelivered = true
// …
}
现在 setter/getter get {
guard anyLocationDelivered else { return nil }
let usedLocation = _location ?? super.location
return usedLocation
}
现在不再记录此错误消息。
关于ios - 来自 CoreMotion.framework 的奇怪 #NullIsland 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64952663/