ios - 位置管理器 :didRangeBeacons not detect the same beacon two times

标签 ios swift ibeacon beacon

后台模式 中测试 ibeacons 时,我发现使用以下方法进行检测存在很大问题:

IN FOREGROUND WORKS FINE

func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {}

我想实现的想法是我自己管理第二次检测到信标的时间,让我靠近信标。

问题是当第二次尝试检测同一个信标时(有时甚至是第一次检测其他信标),出于某种奇怪的原因,这个函数不再被调用,就在第一次检测之后。

The only way is remove battery from beacon (intermittent) or take my beacon and walk Until leaving the detection area (This always works).

最后我使用这个函数来验证:

func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) {
    
    if (state == CLRegionState.inside)
    {
      print("didDetermineState inside!!!!")
    }
    else if (state == CLRegionState.outside)
    {
      print("didDetermineState outside!!!!")
    }
    else
    {
      print("didDetermineState Other!!!!")
    }
  }

只执行这2个选项的一部分,函数又被触发

提前致谢。


更新

考虑this answer , didRangeBeacons 应该不断执行,但我正在试验 didEnterRegion 问题。

我正在使用这两个函数:

 - didRangeBeacons: for beacons visibles in ranging.
 - didEnterRegion: for Geofencing and beacons too

最佳答案

iOS 上的 Beacon ranging 通常仅在您的应用程序位于前台时才有效。 在您的应用程序进入后台后,后台测距限制为 10 秒。如果您也在监控(听起来像您在监控),它还会在任何时候获得额外的 10 秒后台测距时间有一个进入/退出事件——例如如果 CLBeaconRegion 中的所有信标都停止被检测到(退出),或者在退出事件后第一次检测到(进入)之后。这可能解释了您所看到的。

您可以根据要求将背景测距时间延长至 180 秒,但您只能通过特殊的背景模式让它无限期地持续下去。我写了一篇博文对此进行了详细描述 here.

关于ios - 位置管理器 :didRangeBeacons not detect the same beacon two times,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44287010/

相关文章:

ios - 从字符串 ios 获取子字符串?

ios - XCode 8.0 应用构建超慢

objective-c - 在 uikeyboard 顶部添加工具栏

ios - 如何使 Storyboard中的 UILabel 和 UIButton 大写

ios - 类型 'Item' 的值没有成员 'parentCategory'

ios - CollectionView 每个项目的分页起点

swift - 绕过 WatchKit 中的 playHaptic 预定义案例

ios - 如何判断我的设备是否没有看到信标?

ios - 使用 PheripheralManager/CBCentralManager 将 macbook 变成 iBeacon 后找不到

ios - 如何使 CLProximityImmediate 的 iBeacon 前景测距在 iOS 中更快?