iBeacon监控和后台测距 [英] iBeacon monitoring and ranging in background

查看:185
本文介绍了iBeacon监控和后台测距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了几个月的时间开发基于iBeacons的应用程序,我真的很沮丧。

I took several months developing an application based on iBeacons and I'm really frustrated.

一般的想法是,当检测到信标时,会通知用户具有该特定信息的iBeacon。

The general idea is that when a beacon is detected, the user is notified with information specific to that iBeacon.

该应用程序的设计如下,所有iBeacons具有相同的UUID,Major决定建筑物(博物馆,商店...)和未成年人的具体产品(图片,鞋......)。因此,此应用程序可以为多个客户端提供服务。

The application was designed as follows, all iBeacons have the same UUID, the Major determines the building (Museum, shop...) and the Minor the specific product (pictures, shoes...). So this application may serve multiple clients.

当应用程序启动时,我开始使用我们的UUID对区域进行监控和测距。当应用程序处于前台时,一切都很完美。但是在背景或暂停状态下,问题就开始了。在背景或暂停状态下不允许测距。

When the application starts, I begin to do monitoring and ranging for region with our UUID. When the app is in foreground all works perfect. But in background or suspended state the problems starts. Ranging is not allowed on background or suspended state.

我知道当您进入或退出信标区域时,应用程序将在后台启动约5秒。你可以在这五秒钟的时间内完成后续操作,之后iOS会再次暂停你的应用程序。

I know that the app will be launched into the background for about 5 seconds when you enter or exit the region of a beacon. You can here do ranging in the background for this five second period, after which iOS will suspend your app again.

我设法将范围延长至3分钟这里学到的技术背景。我还通过notifyEntryStateOnDisplay = YES得到额外的回调;

I managed to extend ranging for up to 3 minutes in the background with the technique learned here. I also get an extra callback with notifyEntryStateOnDisplay = YES;

但这还不够,如果客户进入应用程序处于后台或暂停状态的区域,他将是收到通知。在额外的3分钟内,如果测距检测到另一个iBeacon,他会收到通知,但是当3分钟后台任务到期时,如果没有触发任何区域退出,他将不会再收到任何通知。

But this is not enough, if a client enters a region with the app in background or suspended state, he will be notified. And during the extra 3 minutes he will be notified if the ranging detects another iBeacon, but when the 3 minutes background task expired, if no region exit is triggered he will not receive any notification again.

这样的场景中没有真正的解决方案吗?我认为这是一个非常常见的情况,我很惊讶没办法处理它。

Is there no real solution in a scenario like this? I think it is a very common scenario and I'm surprised no way to deal with it.

编辑:我试图通过监控两个地区找到问题的解决方案正如David Young在回答中所建议的那样。为了获得更多的进入/退出区域事件。

EDITED: I tried to find a solution to the problem by monitoring two regions as recommended David Young in his response. In order to obtain more events of entry/exit regions.

我添加了我实现的代码,试图监控两个区域。

I added the code I implemented to try to monitor two regions.

但是我做错了而且didRangeBeacons:InRegion:当预期是每秒时,回调每10毫秒触发一次。

but something I have done incorrectly and didRangeBeacons:InRegion: callback is firing every 10 ms when the expected is every second.

On AppDelegate.m ,我在中执行以下操作:didFinishLaunchingWithOptions:

[self.locationManager startMonitoringForRegion:self.beaconRegion];
        [self.locationManager stopRangingBeaconsInRegion:self.beaconRegion];
        [self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
        [self.locationManager startMonitoringForRegion:self.beaconRegion2];
        [self.locationManager stopRangingBeaconsInRegion:self.beaconRegion2];
        [self.locationManager startRangingBeaconsInRegion:self.beaconRegion2];

然后,在 didRangeBeacons:InRegion:

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

     if(beacons.count > 0){
          [self.locationManager stopRangingBeaconsInRegion:region];
          for (CLBeacon *beacon in beacons){
             NSLog(@"beacon detected major: %@ minor: %@", beacon.major,beacon.minor);
          }
           [self.locationManager startRangingBeaconsInRegion:region];   
     }

}

当我运行应用程序时模拟器,并且每个网络的信标都在范围内,消息大约每10毫秒显示在控制台上。

When I run the application on the simulator, and there is a beacon of each network in range, the message is displayed on the console approximately every 10 ms.

我怀疑停止并重启测距是打破预期的回调流,但当只有一个区域在范围内时,回调按预期每秒发生。

I suspect that the stop and restart the ranging is breaking the expected callback flow, but when only one region is in the range, callbacks occur every second as expected.

推荐答案

问题你描述的很常见。除了延长背景测距时间(您已经完成), iOS上没有灵丹妙药

The problem you describe is common. Other than extending background ranging time (which you have already done), there is no magic bullet on iOS.

另外两种技术可能有所帮助。这两种技术都涉及在从一个信标传递到下一个信标时获得新的条目事件

Two additional techniques may help. Both of these techniques involve getting a new entry event as you pass from one beacon to the next:


  1. 获取硬件信标,让您调低发射机功率(我公司的RadBeacon产品允许这样做,因此传输不会重叠。这样,当您从信标移动到信标时,您将获得退出事件,然后是新的输入事件。

  1. Get hardware beacons that allow you to tune down the transmitter power (my company's RadBeacon products allow this) so the transmissions do not overlap. This way you get an exit event then a new enter event as you move from beacon to beacon.

重新设计您的标识符示意图,以便主要字段为致力于识别多达20个不同的区域(基于UUID和主要1-20)。然后,您监控所有这些区域。您的个人信标仍然可以根据需要使用未成年人,特别是作为触发消息传递的密钥。放置信标时,请确保没有重叠传输的信标共享相同的主信号。当您从一个移动到另一个时,这将确保新的背景录入事件。

Redesign your identifier schene so the major field is dedicated to identifying up to 20 different regions (based on UUID and major 1-20). You then monitor for all of these regions. Your individual beacons can still use the minor however you want and specifically as the key to trigger messaging. When placing your beacons, you make sure that none with overlapping transmissions share the same major. This will ensure a new background entry event as you move from one to the other.

这篇关于iBeacon监控和后台测距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆