【问题标题】:CoreLocation kCLErrorDomain error 5CoreLocation kCLErrorDomain 错误 5
【发布时间】:2013-07-18 00:26:10
【问题描述】:

我将CLRegion 子类化以通过覆盖containsCoordinate: 来支持多边形,以使用光线投射逻辑而不是原始的距离计算逻辑。子类通过普通方法(initCircularRegionWithCenter:radius:identifier:)初始化,然后将CLLocationCoordinate2ds 作为NSValues 添加到可变数组中。这些坐标在光线投射逻辑期间使用。

一旦我尝试使用 CLRegion 子类,我的应用程序逻辑就会遇到大量错误,以及以下错误:

2013-07-18 16:46:44.515 Geofencing[4816:907] (identifier 6C11CBAF-3EE4-4257-9D75-9724F4349B5D) <+39.86605072,-75.54420471> radius 186.54m: Error Domain=kCLErrorDomain Code=5 "The operation couldn’t be completed. (kCLErrorDomain error 5.)"

我还尝试了一个不同的子类,它不修改任何方法,但添加了一个从 NSDictionary 读取元数据的方法。我遇到了同样的错误。

发生了什么事?子类化 CLRegion 可行吗?

【问题讨论】:

标签: objective-c cocoa-touch core-location clregion


【解决方案1】:

我不想回答自己的问题,但我已经找到了解决问题的方法。 kCLErrorDomain 代码/错误 5 表示您已尝试监控超过 20 个 CLRegions。就我而言,这两个子类都监控了 20 多个地区。

【讨论】:

  • 查看其他答案;错误代码 5 不表示这一点,它似乎是各种错误情况的“全部”代码。
  • 表示这一点。如果您尝试添加 > 20 个信标,您确实会收到此消息。
  • 也发生在我身上,添加 25 个信标会返回 5 个上述错误代码。
  • 删除监控区域的解决方案是什么?我尝试使用我注册的 stopMonitoringForRegion,但没有成功。
  • 你可以在监控 1 个区域时得到这个,这不应该是CoreLocation kCLErrorDomain error 5 的公认答案,即使它是 OP 的答案,也许更新问题,这样其他人就不会到这里结束
【解决方案2】:

如果您这样做也会发生:

停止监控区域

[self.manager stopMonitoringForRegion:region];

并在不久之后请求所有受监控区域的状态:

for (CLRegion *region in self.manager.monitoredRegions) {
    [self.manager requestStateForRegion:region];
}

您将获得 kCLErrorDomain 5,因为 IOS 似乎已禁用对该区域的监控,但尚未将其从受监控的区域数组中删除

monitoringDidFailForRegion CLCircularRegion (identifier:'Home', center:<...>, radius:102.00m) The operation couldn’t be completed. (kCLErrorDomain error 5.)
monitoredRegion: CLCircularRegion (identifier:'Home', center:<...>, radius:102.00m)
monitoredRegion: CLBeaconRegion (identifier:'BeaconHome', uuid:<..., major:(null), minor:(null))
monitoredRegion: CLCircularRegion (identifier:'D...', center:<...>, radius:101.00m)
monitoredRegion: CLCircularRegion (identifier:'W...', center:<..>, radius:51.00m)

要解决这个问题,请执行以下操作:

- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
    NSLog(@"monitoringDidFailForRegion %@ %@",region, error.localizedDescription);
    for (CLRegion *monitoredRegion in manager.monitoredRegions) {
        NSLog(@"monitoredRegion: %@", monitoredRegion);
    }
    if ((error.domain != kCLErrorDomain || error.code != 5) &&
        [manager.monitoredRegions containsObject:region]) {
        NSString *message = [NSString stringWithFormat:@"%@ %@",
            region, error.localizedDescription];
        [AlertView alert:@"monitoringDidFailForRegion" message:message];
    }
}

【讨论】:

  • 我到底发生了什么。如果解决方案只是显示警报会很好。
  • 谷歌搜索后,我发现了这个cocoanetics.com/2014/05/… ..它有效..耶!!。
  • 在相同的场景下我可以做些什么来避免这个错误?我需要停止监控一个区域并同时开始监控另一个区域。
【解决方案3】:

另外:如果您使用 iBeacons 进行测试,则不能使用 iOS 模拟器。

【讨论】:

    【解决方案4】:

    当您的纬度和经度值没有意义时,也可以取回此错误代码。 (例如,我已经转置了它们,并被这个错误困扰了一段时间。)

    【讨论】:

    • 我搜索了这个问题多长时间,发现我也转置了它们:-D 谢谢!
    • 这很有帮助,我注意到用户的设备上似乎无法获得准确的 gps
    【解决方案5】:

    如果添加CLRegionnil,也会出现此错误。

    【讨论】:

    • 这也是,这可能是一个全面的错误代码。懒惰的苹果工程师 xD
    【解决方案6】:

    如果有人还在为此苦苦挣扎,请看这里:

    在我的情况下,我必须在调用 startMonitoring 之前调用 requestAlwaysAuthorization,它就像魅力一样!

    locationManager.requestAlwaysAuthorization()
    
    let currRegion = CLCircularRegion(center: CLLocationCoordinate2D(latitude: LAT, longitude: LONG, radius: 100, identifier: "MyLocation")
    currRegion.notifyOnEntry = true
    
    locationManager.startMonitoring(for: region)
    

    顺便说一句,我非常感谢https://shrikar.com/swift-tutorial-corelocation-and-region-monitoring-in-ios-8/

    【讨论】:

      【解决方案7】:

      我收到此错误是因为我没有启动蓝牙。 所以...不要忘记启动您的蓝牙 ;)

      【讨论】:

        猜你喜欢
        • 2016-07-23
        • 2012-12-03
        • 2014-05-26
        • 2010-11-27
        • 2012-03-20
        • 2016-01-26
        • 1970-01-01
        • 2015-12-09
        • 2015-06-03
        相关资源
        最近更新 更多