Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

didFailWithError: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"

I want to get the current location, but instead I get an error.

This is a snippet of my view controller.

- (void)viewDidLoad {
    self.locationManager = [[CLLocationManager alloc] init];
    [locationManager setDelegate:self];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
    [locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager 
     didUpdateLocations:(NSArray<CLLocation *> *)locations {
    // I would get the latest location here
    // but this method never gets called
}
- (void)locationManager:(CLLocationManager *)manager 
       didFailWithError:(NSError *)error {
    NSLog(@"didFailWithError: %@", error);
}

I'm expecting the delegate method locationManager:didUpdateLocations: to get called, but instead, only locationManager:didFailWithError: gets called, and prints this:

didFailWithError: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)" 
like image 980
Luca Avatar asked May 17 '11 15:05

Luca


5 Answers

If you are using the simulator:

  1. Press command + shift + , in Xcode to open the scheme editor
  2. Select the Run scheme
  3. Go to the Options tab
  4. Check ✅ Allow Location Simulation
  5. Select a Default Location in the dropdown

Selecting None as your Default Location may have caused the problem.

like image 147
sKhan Avatar answered Nov 05 '22 13:11

sKhan


  1. Check that you actually have a valid WiFi and 3G connection

    ...if you do, then:

  2. Go to settings and reset your location services

  3. Reset your network settings

This should take care of that issue. It is device/network related not app related. It's annoying especially if your app is dependent on location services and the device is WiFi only and people give negative ratings on the AppStore... Pardon me, I'm getting a bit emotional there.

like image 21
MeM Avatar answered Nov 05 '22 14:11

MeM


Simply ignore this error and wait for more updates or a different error.

The docs for the location manager say that this error is temporary. It's letting you know that it failed to immediately retrieve a location, but it continues to try. "In such a situation, you can simply ignore the error and wait for a new event." Which is a really boneheaded way to use a method named locationManager:didFailWithError: - Thanks Apple!

Apple Documentation

like image 24
Ray Lillywhite Avatar answered Nov 05 '22 13:11

Ray Lillywhite


Try restarting the simulator (assuming that's what you're using).

After trying everything else this worked for me.

like image 19
Ian Avatar answered Nov 05 '22 14:11

Ian


A restart of the simulator didn't work for me.

I had to clear everything via "iOS Simulator" >> "Reset Content and Settings....

like image 14
Brandon O'Rourke Avatar answered Nov 05 '22 13:11

Brandon O'Rourke