按下刷新按钮后,我在更新用户位置时遇到问题。我有以下代码。编译器没有显示任何错误,但print after refresh
不起作用且没有数据。谁能指出我正确的方向如何解决它?
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.requestLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.first {
print("Coordinates: \(location)")
}
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("errorer")
}
然后我有以下刷新代码:
@IBAction func refreshJobData(_ sender: Any) {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.last {
print("Coordinates after Refresh: \(location)")
}
}