5

Using iBeacon and CoreLocation I'm receiving the following error:

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

Unless I'm missing it, there doesn't seem to be a clear reference on Apple for what each of the error code means.

Can anyone interpret this error code?

The error calls from:

- (void)locationManager:(CLLocationManager *)manager rangingBeaconsDidFailForRegion:    (CLBeaconRegion *)region withError:(NSError *)error{
NSLog(@"%@", error);
}

- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error{
NSLog(@"%@", error); }
rmaddy
  • 314,917
  • 42
  • 532
  • 579
BEEKn
  • 244
  • 2
  • 5
  • 1
    Look at the documentation for [CLError](https://developer.apple.com/library/mac/documentation/CoreLocation/Reference/CoreLocationConstantsRef/Reference/reference.html), and the header file ``CLError.h`` – quellish Apr 24 '14 at 18:24

3 Answers3

11

Look at the docs for CLError. Value 16 is kCLErrorRangingUnavailable.

The docs say:

Ranging is disabled. This might happen if the device is in Airplane mode or if Bluetooth or location services are disabled.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 1
    Yes, thanks for that - although it's clearly a bug with Apple. Location services were clearly working as the beacons were being ranged, and then you get this brief error which then auto corrects itself. So the beacons are ranging fine, you then get the error message, and it ranges fine again. We didn't touch the phone or beacon and based on monitoring the beacon there was no change in signal strength. Thanks for replying! – BEEKn Nov 24 '13 at 13:37
  • Turning the phone on and off fixed it for me. – shim Mar 18 '14 at 04:50
3

You can use the CLError enum and the error returned to your location manager to handle location errors in a specific and clear way.

It looks like this:

func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
  if let locationError = CLError(rawValue: error.code) {
    switch locationError {
    case .Denied:
      println("Location permissions denied")
    default:
      println("Unhandled error with location: \(error)")
    }
  }
}

Thanks to @rmaddy for the CLError tip.

SimplGy
  • 20,079
  • 15
  • 107
  • 144
1

Also, make sure that you have Background App Refresh enabled. For some reason with my iPhone 5s on iOS 7.1.1, beacons would not range when Background App Refresh is disabled, even if my app is in the foreground. Turning on App Refresh caused beacons to range again.

collinotis
  • 11
  • 1