【发布时间】:2019-09-17 11:48:19
【问题描述】:
我正在制作一个天气应用程序,它通过发送当前坐标来获取温度信息。所以我正在使用 CLLocationManager。我还没有发出任何 HTTP 请求。我想在我的屏幕上看到“位置不可用”,但它不起作用。
我正在关注一个教程并编写了完全相同的代码,但在教程中它正在工作。在调试会话中,它不会跳转到 didFailwithError 或 didUpdateLocations 方法。我在我的 info.plist 和我手机的定位服务是开放的。根据我的研究 locationManager.startUpdatingLocation() 应该自动调用 这些方法,但是当我运行我的应用程序时,UI 上什么也没有显示。
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("you got the location")
}
//Write the didFailWithError method here:
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print(error)
cityLabel.text = "Location Unavaiable"
}
和
let locationManager = CLLocationManager ()
override func viewDidLoad() {
super.viewDidLoad()
//TODO:Set up the location manager here.
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
【问题讨论】:
标签: ios swift4 cllocationmanager