gpt4 book ai didi

ios - 更新位置时出错操作无法完成。 (kCLErrorDomain 错误 0。)

转载 作者:行者123 更新时间:2023-11-28 16:11:37 33 4
gpt4 key购买 nike

我收到这个错误:

Error while updating location The operation couldn’t be completed. (kCLErrorDomain error 0.)

我的问题是,几乎每次我运行模拟器时都会显示此错误,并且在模拟器运行的整个过程中一直显示该错误(每次我向 viewController 显示 map 时,它都会向我显示此错误)。最奇怪的是有时这个错误是零,一切都很好。在实际设备上它工作正常,但是当我想尝试一些带有位置的东西(在模拟器上)时,我必须重新启动模拟器大约 7 次直到它工作。

这是 Info.plist:

enter image description here

我的位置是自定义的:

enter image description here

这是我的代码:

func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("Error while updating location " + error.localizedDescription)

let alertController = UIAlertController(title: "Sorry!", message: "We were unable to find your location", preferredStyle: UIAlertControllerStyle.Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(defaultAction)

presentViewController(alertController, animated: true, completion: nil)
print("Error...")
}

我的问题是为什么它只在某些时候有效?谢谢:)

最佳答案

请检查一下并告诉我。在模拟器上做,然后尝试。 enter image description here

更新:

我刚刚尝试过,它工作正常,当我将位置指定为 NONE 时出现同样的错误。工作代码

import CoreLocation
Conform CLLocationManagerDelegate
Create var locationManager:CLLocationManager!
Plist - NSLocationAlwaysUsageDescription add.

override func viewDidLoad() {
super.viewDidLoad()
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("locations = \(locations)")
}

func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("Error while updating location " + error.localizedDescription)

let alertController = UIAlertController(title: "Sorry!", message: "We were unable to find your location", preferredStyle: UIAlertControllerStyle.Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(defaultAction)

presentViewController(alertController, animated: true, completion: nil)
print("Error...")
}

我正在使用上面的代码正确获取位置,如果我没有为模拟器放置位置,则会出现以下错误:

更新位置时出错操作无法完成。 (kCLErrorDomain 错误 0。)

正确运行时:locations = [<+37.33233141,-122.03121860> +/- 5.00m(速度 0.00 mps/航向 -1.00)@ 2016 年 9 月 14 日,巴基斯坦标准时间下午 2:34:46]

关于ios - 更新位置时出错操作无法完成。 (kCLErrorDomain 错误 0。),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39486532/

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