CLLocationManager kCLErrorDomain Codes?

喜夏-厌秋 提交于 2019-12-05 09:03:05

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!