0nd*_*re_ 1 xcode cllocationmanager ios swift
我收到此错误:
\n\n\n\n\n更新位置时出错操作无法完成\xe2\x80\x99。\n(kCLErrorDomain 错误 0。)
\n
我的问题是,几乎每次运行模拟器时都会显示此错误,并且在模拟器运行的整个过程中它都会一直显示该错误(每次我向 viewController 提供地图时,它都会显示此错误)。最奇怪的是有时会出现此错误错误为零,一切都很好。在实际设备上,它工作正常,但是当我想尝试使用位置(在模拟器上)时,我必须重新启动模拟器大约 7 次,直到它工作为止。
\n\n这是Info.plist:
\n\n\n\n我的位置是自定义的:
\n\n\n\n这是我的代码:
\n\nfunc locationManager(manager: CLLocationManager, didFailWithError error: NSError) {\n print("Error while updating location " + error.localizedDescription)\n\n let alertController = UIAlertController(title: "Sorry!", message: "We were unable to find your location", preferredStyle: UIAlertControllerStyle.Alert)\n let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)\n alertController.addAction(defaultAction)\n\n presentViewController(alertController, animated: true, completion: nil)\n print("Error...")\n }\nRun Code Online (Sandbox Code Playgroud)\n\n我的问题是为什么它只是有时有效?\n谢谢你:)
\n更新:
\n\n我刚刚尝试过,工作正常,当我将位置指定为NONE时,会出现相同的错误时,会出现相同的错误。\n工作代码
\n\nimport CoreLocation\nConform CLLocationManagerDelegate\nCreate var locationManager:CLLocationManager!\nPlist - NSLocationAlwaysUsageDescription add.\n\noverride func viewDidLoad() {\n super.viewDidLoad()\n locationManager = CLLocationManager()\n locationManager.delegate = self\n locationManager.desiredAccuracy = kCLLocationAccuracyBest\n locationManager.requestAlwaysAuthorization()\n locationManager.startUpdatingLocation()\n}\n\nfunc locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {\n print("locations = \\(locations)")\n}\n\nfunc locationManager(manager: CLLocationManager, didFailWithError error: NSError) {\n print("Error while updating location " + error.localizedDescription)\n\n let alertController = UIAlertController(title: "Sorry!", message: "We were unable to find your location", preferredStyle: UIAlertControllerStyle.Alert)\n let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)\n alertController.addAction(defaultAction)\n\n presentViewController(alertController, animated: true, completion: nil)\n print("Error...")\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我使用上面的代码正确获取位置,如果我没有放置模拟器的位置,则会出现以下错误:
\n\n更新位置时出错 无法完成操作\xe2\x80\x99。(kCLErrorDomain 错误 0。)
\n\n正确运行时:\n位置 = [<+37.33233141,-122.03121860> +/- 5.00m(速度 0.00 mps / 航向 -1.00)@ 9/14/16, 2:34:46 PM 巴基斯坦标准时间]
\n| 归档时间: |
|
| 查看次数: |
6138 次 |
| 最近记录: |