【问题标题】:Error while updating location The operation couldn’t be completed. (kCLErrorDomain error 0.)更新位置时出错 操作无法完成。 (kCLErrorDomain 错误 0。)
【发布时间】:2017-01-22 00:42:01
【问题描述】:

我收到此错误:

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

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

这是 Info.plist:

我的位置是自定义的:

这是我的代码:

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...")
    }

我的问题是为什么它只有时有效? 谢谢你:)

【问题讨论】:

  • 您可以查看此链接。 stackoverflow.com/questions/6032976/…
  • 我已经看到了这个问题,但我找不到解决方案:/
  • 然后选择模拟器菜单>调试>位置>设置自定义或选择任何0r检查互联网连接
  • 我的互联网连接应该没问题(我坐在距离路由器 2 米的地方,而且互联网速度很快)。

标签: ios swift xcode cllocationmanager


【解决方案1】:

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

更新:

我刚刚尝试过,它工作正常,当我将位置分配为 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。)

当它正确运行时: 位置 = [ +/- 5.00m(速度 0.00 mps / 路线 -1.00)@ 2016 年 9 月 14 日,巴基斯坦标准时间下午 2:34:46]

【讨论】:

  • 将我的 xcode 更新为 xcode8 并且错误消失了 :) ,但谢谢 +1
【解决方案2】:

对于 Xcode 11.5,此菜单已移至(Simulator > Features > Location)! 另外,请在选择模拟位置后重新安装应用程序。

第二个要检查的地方是(Xcode > Debug > Simulate Location)。在模拟器中选择“自定义位置”时。

【讨论】:

    猜你喜欢
    • 2016-10-22
    • 2013-10-21
    • 2015-06-03
    • 2011-08-27
    • 2014-03-04
    • 2010-11-24
    • 2018-10-24
    • 1970-01-01
    • 2010-11-27
    相关资源
    最近更新 更多