我将我的对象设置为 locationManager 的委托(delegate),并调用了 didChangeAuthorizationStatus 方法,它执行以下操作:
func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status == CLAuthorizationStatus.AuthorizedWhenInUse {
self.locationManager.startUpdatingLocation()
}
}
我也有这个方法,它永远不会被调用:
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
if locations.count == 0 {
return
}
//Do stuff
}
关于为什么不调用它有什么想法吗?我想被释放的对象是一个选项,但它也会在它到达 authorizationStatus 方法时被释放。
最佳答案
这太晚了,但当我遇到同样的问题时,我偶然发现了这个问题(调用了 didChangeAuthorizationStatus
而不是 didUpdateLocations
)。当然,这与代码无关,而是我在没有设置位置的模拟器中进行测试。因此从未找到该位置,导致 didUpdateLocations
永远不会被调用。
要解决此问题...在模拟器中转至 Debug -> Location-> <choose location>
.
编辑 还应该注意的是 locationManager:didFailWithError:
如您所料,如果模拟器中未设置位置,则会运行。
关于ios - didUpdateLocations 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26178483/