具有不可靠结果的iBeacon监控(didEnterRegion& didExitRegion)

时间:2016-04-04 14:47:56

标签: objective-c ios9 core-location ibeacon estimote

我目前正在开发一款适用于iBeacon的iOS应用程序,以便能够执行某些操作并接收通知。 测距工作完美无缺,但我在灯塔监控和通知方面遇到了麻烦。我已经研究了很多关于这个主题的内容,我知道CoreLocation框架通常有这样的问题,但我想知道其他开发人员是如何修复/接近这个问题的。

基本上,当我触发didEnterRegion和didExitRegion方法时,我会显示本地通知。不幸的是,这两种方法经常被解雇(以不可靠的方式),即使iBeacon就在它旁边,虽然有时候工作得很完美,这使得它更加烦人。 我已经尝试降低iBeacon广告时间间隔,尽管它有所帮助,但它并没有完全解决问题。现在,我正在尝试使用逻辑过滤器,如果在最后X分钟内发生了进入或退出事件,我会忽略触发通知(我正在考虑5到15之间的“魔术”数字)。

是否有人遇到同样的问题?是否会在情况中添加第二个iBeacon? (也许监视它们,并逻辑过滤出口并根据这两个输入输入事件?)。 我还在考虑添加另一层数据来显示通知,可能是基于GPS或Wifi信息。有人试过吗?

还有其他想法吗?我愿意接受任何建议。

以防万一,我正在使用Estimote iBeacons和iOS9(Objective-c)。

谢谢你的时间!

2 个答案:

答案 0 :(得分:2)

Intermittent region exit/entry events are a common problem, and are typically solved with a timer-baded software filter exactly as you suggest. The specifics of how you set up the filter (the minimum time to wait for a re-entry after an exit before processing exit logic) varies for each use case so it is good to have it under your control.

Understand that region exits are caused by iOS not detecting any Bluetooth advertisements from a beacon in the CLBeaconRegion for 30 seconds. If two detected packets are 31 seconds apart, you will get a region exit and then a region entry one second later.

This commonly happens with low signal levels. If an iOS device is on the outer edge of the beacon's transmission range, only a small percentage of packets will be received. With a beacon transmitting at 1Hz, if 30 packets in a row are missed, the iOS device will get an exit event.

There are several things you can do to reduce this problem in a specific area where you want solid coverage:

  1. Turn your beacon transmitter power up to the maximum. This will give stronger signal levels and fewer missed packets in the area you care about.

  2. Turn the advertising rate to the maximum. Advertising at 10 Hz gives 10x as many packets to receive as 1 Hz.

  3. If needed add additional beacons with the same identifier to increase coverage.

Of course, there are costs to the above, including reduced battery life at high advertising rates and transmitter power levels.

Even if you do all of the above, you still need the software filter, because there will always be a point where you are on the edge if the nearest beacon's transmission radius.

You can see an example of software filter code in my answer here.

答案 1 :(得分:1)

信标发出脉冲信号。测距还执行间歇扫描(大约每100毫秒)。这意味着您的设备可能会连续几秒钟丢失信标,这可能会导致您遇到的结果。您可以在此方法中记录信标RSSI值:

- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)iBeacons inRegion:(CLBeaconRegion *)region

我相信在看到didExitRegion被调用之前你会看到很多零值。这不是您的代码或信标的错误。这只与发射信号或检测信号不变的事实有关。他们是脉动的。当信标与您的设备位于同一桌面时会出现这些问题,并且当信号被物理对象和人员阻挡时,可能会在现实世界设置中被夸大。

如果您的灯塔在附近,我会使用测距来更准确地确定。请注意,测距,特别是在背景中可能会有很大的电池消耗。