CLLocationManager kCLErrorDomain Codes?

2019-04-30 14:08发布

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); }

3条回答
Summer. ? 凉城
2楼-- · 2019-04-30 14:26

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.

查看更多
Bombasti
3楼-- · 2019-04-30 14:29

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.

查看更多
Lonely孤独者°
4楼-- · 2019-04-30 14:32

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.

查看更多
登录 后发表回答