2016-09-14 122 views
0

我收到此错误:更新位置时出错操作无法完成。 (kCLErrorDomain误差为0)

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

我的问题是,这个错误显示几乎每次我运行模拟器,它不断显示我的错误整体时间模拟器运行(每当我给视图控制器一个地图它显示我这个错误)。最奇怪的是,有时这个错误是零,一切都很好。在一个实际的设备上它工作正常,但是当我想尝试一些位置(在模拟器上)时,我必须重新启动模拟器大约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...") 
    } 

我的问题是,为什么有时只有作品? 谢谢:)

+0

您可以点击此链接。 http://stackoverflow.com/questions/6032976/didfailwitherror-error-domain-kclerrordomain-code-0-the-operation-couldn-t-be –

+0

我已经看到了这个问题,我找不到解决方案:/ –

+1

然后选择模拟器菜单>调试>位置>设置自定义或选择任何0r检查互联网连接 – Sandy

回答

1

请检查并让我知道。在模拟器上做,然后尝试。 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)

当它运行时正确: 位置= [< + 37.33233141,-122.03121860> +/-5.00米(速度0.00 MPS /当然-1.00)@ 16年9月14日,2 :34:46 PM巴基斯坦标准时间]

+0

这不是问题......:/我有权利 –

+0

更新我的xcode到xcode8和错误消失:),但谢谢你+1 –

相关问题