5

使用 iBeacon 和 CoreLocation 我收到以下错误:

错误域=kCLErrorDomain 代码=16 “操作无法完成。(kCLErrorDomain 错误 16。)

除非我错过了它,否则苹果似乎没有明确的参考来说明每个错误代码的含义。

谁能解释这个错误代码?

错误调用来自:

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

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

3 回答 3

11

查看CLError. 值 16 是kCLErrorRangingUnavailable

文档说:

测距被禁用。如果设备处于飞行模式或者蓝牙或定位服务被禁用,则可能会发生这种情况。

于 2013-11-23T18:01:16.330 回答
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.

于 2015-06-08T12:03:26.577 回答
1

此外,请确保您启用了后台应用程序刷新。出于某种原因,在 iOS 7.1.1 上使用我的 iPhone 5s 时,即使我的应用程序在前台,当后台应用程序刷新被禁用时,信标也不会起作用。开启 App Refresh 会导致信标再次覆盖范围。

于 2014-04-24T18:17:02.710 回答