gpt4 book ai didi

ios - 尝试获取用户位置时出错(快速)

转载 作者:行者123 更新时间:2023-11-30 12:34:50 25 4
gpt4 key购买 nike

我正在尝试获取用户在 iOS 上的位置。我使用 CLLocationManagerDelegate 来实现它。

if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.requestLocation()
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.first
print("locations = \(location?.coordinate.latitude) \(location?.coordinate.longitude)")
}

但我收到此错误

2017-03-24 18:03:57.183 *** Assertion failure in -[CLLocationManager requestLocation], /BuildRoot/Library/Caches/com.apple.xbs/Sources/CoreLocationFramework_Sim/CoreLocation-2100.0.34/Framework/CoreLocation/CLLocationManager.m:867
2017-03-24 18:03:57.194 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Delegate must respond to locationManager:didFailWithError:'

实现locationManager:didFailWithError:

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print(error.description)
}

我有这个警告

Instance method 'locationManager(:didFailWithError:)' nearly matches optional requirement 'locationManager(:didFailWithError:)' of protocol 'CLLocationManagerDelegate'

又出现这个错误

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Delegate must respond to locationManager:didFailWithError:'

不知道哪里错了。 locationManager:didFailWithError: 已实现,但我有同样的错误。

最佳答案

更改为

@objc(locationManager:didFailWithError:)
func locationManager(_ manager: CLLocationManager, didFailWithError error: NSError) {
print(error.localizedDescription)
}

对我的情况有帮助

关于ios - 尝试获取用户位置时出错(快速),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43010231/

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