Reputation: 3631
I am getting this error:
Error while updating location The operation couldn’t be completed. (kCLErrorDomain error 0.)
My problem is that this error shows almost every time I run the simulator and it keeps showing me that error a whole time that simulator runs (every time I present viewController with a map it shows me this error).The weirdest thing is that sometimes this error is nil and everything is fine. On an actual device it works fine, but when I want to try something with location (on simulator) I have to restart the simulator about 7 times until it works.
This is Info.plist:
My Location is custom:
This is my code:
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...")
}
My question is why it works only sometimes? Thank you :)
Upvotes: 1
Views: 6422
Reputation: 886
For Xcode 11.5, this menu was moved to (Simulator > Features > Location)! Also, reinstall the app after selecting a simulated location.
The second place to check is (Xcode > Debug > Simulate Location). When "Custom location" selected in Simulator.
Upvotes: 2
Reputation: 5060
Please, check this and let me know. Do it on simulator and then try.
Updated:
I have just tried, it's working fine same error comes when I assigned location as NONE. Working Code
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...")
}
I am getting location properly using above code and if I did not put the Location for Simulator then getting following error:
Error while updating location The operation couldn’t be completed. (kCLErrorDomain error 0.)
When it runs correctly: locations = [<+37.33233141,-122.03121860> +/- 5.00m (speed 0.00 mps / course -1.00) @ 9/14/16, 2:34:46 PM Pakistan Standard Time]
Upvotes: 5