gpt4 book ai didi

ios - 委托(delegate)必须响应 locationManager :didFailWithError: even though implemented didFailWithError method

转载 作者:可可西里 更新时间:2023-11-01 17:13:29 25 4
gpt4 key购买 nike

出于某种原因 Xcode 认为我没有实现 CLLocationManagerDelegate 协议(protocol)的 didFailWithError 方法

enter image description here enter image description here

我看不出我做错了什么,因为我确实是从另一个 SO post 复制的那就是说这个 didFailWithError 方法已针对 Swift 3 进行了更新。所以我不明白为什么 Xcode 认为我没有实现 didFailWithError

任何见解将不胜感激!

代码

class OptionsViewController: UIViewController,
CLLocationManagerDelegate {
var locationManager: CLLocationManager = CLLocationManager()

override func viewDidLoad() {
//Ask user for location
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest

//Use users current location if no starting point set
if CLLocationManager.locationServicesEnabled() {
if CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse
|| CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways {
locationManager.requestLocation()
}
else{
locationManager.requestWhenInUseAuthorization()
}
}
else{
//Alert user to open location service, bra bra bra here...
}
}

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("error:: \(error)")
}

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
print("didChangeAuthorization")
if status == CLAuthorizationStatus.authorizedWhenInUse
|| status == CLAuthorizationStatus.authorizedAlways {
locationManager.requestLocation()
}
else{
//other procedures when location service is not permitted.
}
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("Did update location called")
// let locValue:CLLocationCoordinate2D = manager.location!.coordinate
// print("locations = \(locValue.latitude) \(locValue.longitude)")
if locations.first != nil {
print("location:: (location)")
}

}

最佳答案

Aaaandd 我意识到这是 b/c 我需要使用特定类型的 Error(特别是 Swift.Error)这是 didFailWithError 的正确方法声明:

func locationManager(_ manager: CLLocationManager, didFailWithError error: Swift.Error) {

关于ios - 委托(delegate)必须响应 locationManager :didFailWithError: even though implemented didFailWithError method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43578473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com