我正在使用Swift 5.2开发应用程序,试图获取当前位置,但是遇到了这个问题:
由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'代理必须响应locationManager:didUpdateLocations:'
我已经创建了locationManager:
let locationManager = CLLocationManager()
在viewDidLoad()中添加了授权请求和当前位置:
locationManager.requestWhenInUseAuthorization()
locationManager.requestLocation()
委托:
locationManager.delegate = self
并使用didUpdateLocations()创建扩展名:
extension WeatherViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("123")
}
}
我是新手,很快,在这个问题的其他类似问题中也没有找到适合我的解决方案
尝试
class WeatherViewController:UIViewController,CLLocationManagerDelegate
和扩展名WeatherViewController {}