通过iBeacon Monitoring& amp; amp; amp; amp; Ranging vs CoreBluetooth scanForPeripheralsWithServices [英] Detecting beacons via iBeacon Monitoring & Ranging vs CoreBluetooth scanForPeripheralsWithServices

查看:191
本文介绍了通过iBeacon Monitoring& amp; amp; amp; amp; Ranging vs CoreBluetooth scanForPeripheralsWithServices的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于iOS对想要扫描BLE信标外设的应用程序所施加的限制存在很多困惑。
阅读了几篇博客和Stack Overflow答案后,我想看看我是否正确理解了所有问题。如果有什么我误解或错过了,请纠正我。我只提到iOS 7及更高版本,专注于检测而不是连接(你可以使用iBeacon Monitoring& Ranging API连接到CLBeacon吗?)。

There is a lot of confusion regarding the restrictions that are applied by the iOS on apps that want to scan BLE beacons\peripherals. After reading several blogs and Stack Overflow answers, I want to see if I understand all the issues correctly. Please correct me if there is anything I misunderstood or missed. I refer only to iOS 7 and above, and focus on detection and not connection (Can you connect to a CLBeacon using the iBeacon Monitoring & Ranging API?).

信标的选项很明确 - 使用通用BLE外设或使用在 iBeacon格式(此外,非标准外设可以在adv-packet中以iBeacon格式进行通告,在扫描响应数据包中以不同格式进行通告。)

The options for the beacons are clear - Use a general purpose BLE peripheral or use a BLE peripheral that advertises in the iBeacon format (Also, a non-standard peripheral can advertise in the iBeacon format in the adv-packet and a different format in the scan-response packet).

一般限制


  • iBeacon测距会让您知道您周围的信标。您必须指定信标预先通告的ProximityUUID(无一般扫描)。将使用最近找到的CLBeacon对象数组每秒调用 didRangeBeacons 。距离信标的距离及其准确度由iOS使用一些机密算法计算,只有Apple的开发人员才知道(该算法基于rssi值和信标所宣传的rssi-at-1米校准字节)。每次进入或退出某个区域时,您也可以使用iBeacon Monitoring呼叫代理人 - 再次,您必须指定您要查找的ProximityUUID(您还可以指定一个主要和次要)。 退出某个地区是指一段时间没有收到任何广告,因此不能立即进行。可以同时监控每台设备的区域数量限制为20 - 这意味着如果其他应用同时进行监控,则您的应用可能无法监控\ nrange(对吗?)。

  • CoreBluetooth - 您还可以检测信标广告中的其他广告结构。如果信标也以iBeacon格式进行广告,您无法看到iBeacon字段(ProximityUUID,主要,次要......),尽管它们是在标准的制造商特定广告结构下发送的,您可以在其他情况下看到。

  • iBeacon Ranging will let you know which beacons are around you. You must specify the ProximityUUID that the beacons advertise beforehand (no "general" scanning). didRangeBeacons will be called every second with an array of CLBeacon objects that were found recently. The distance from the beacon and its accuracy are calculated by the iOS using some confidential algorithm that only Apple's developers really know (The algorithm is based on the rssi values and the rssi-at-1-meter calibration byte that the beacon advertises). You can also use iBeacon Monitoring to call a delegate every time you enter or exit a region - again you must specify the ProximityUUID that you are looking for (you can also specify a major & minor). "Exiting a region" is defined by some time of not receiving any advertisement, and therefore cannot be immediate. The number of regions that can be ranged\monitored simultaneously per device is limited to 20 - This means that if other apps do monitoring\ranging at the same time, your app may not be able to monitor\range (right?).
  • CoreBluetooth - You can also detect other ad-structures in the beacon's advertisement. If the beacon advertises in iBeacon format too, you cannot see the iBeacon fields (ProximityUUID, major, minor...), despite the fact that they are sent under a standard "Manufacturer Specific" ad-structure that you can see in other cases.

在前台运行 - 限制较少的用例:

Running in the Foreground - The less restricted use-case:


  • iBeacon测距和监控 - 没有进一步的限制。

  • CoreBluetooth - 传递 nil serviceUUIDs scanForPeripheralsWithServices 将扫描所有外围设备。在选项中将 CBCentralManagerScanOptionAllowDuplicatesKey 作为 YES 传递将使 didDiscoverPeripheral 为同一个peripheral \ beacon多次调用(我假设你使用定时器检测到广告已经有一段时间没有收到,并假设用户退出了region)。

  • iBeacon Ranging and Monitoring - no further restrictions.
  • CoreBluetooth - Passing nil in the serviceUUIDs of scanForPeripheralsWithServices will scan for all peripherals. Passing CBCentralManagerScanOptionAllowDuplicatesKey as YES in the options will make the didDiscoverPeripheral to be called multiple times for the same peripheral\beacon (I assume that using a timer you detect the advertisement was not received for some time and assume that the user exited the "region").

在后台运行 - 限制性更强的用例:

Running in the Background - The more restricted use-case:


  • iBeacon Ranging无法直接使用。 iBeacon Monitoring将调用 didEnterRegion 并为应用程序运行时间提供6秒 - 您可以在其中开始测距(例如,检测主要和次要)。由于iOS打开和关闭扫描以保持电池电量,因此检测可能不会立即进行。如果您输入具有相同ProximityUUID的多个信标的区域,并且您监视此UUID而没有特定的主要和\\或未成年人,则在您开始接收时将调​​用 didEnterRegion 来自第一个信标的信号 - 但是,如果你没有退出第一个信标的区域并且你也进入了第二个信标的区域,应用程序将不会再次被唤醒( didEnterRegion 将不再被调用)因此你无法开始测距以检测第二个信标的主要&次要。该应用程序不能简单地弹出到前台,但可以创建本地通知和其他后台操作。

  • CoreBluetooth - 根据核心蓝牙后台处理 scanForPeripheralsWithServices 可以在后台使用,但您必须至少指定一个serviceUUID。 didDiscoverPeripheral 将获得10秒的运行时间。使用 CBCentralManagerScanOptionAllowDuplicatesKey 将无效 - didDiscoverPeripheral 将为每个外设调用一次。因此,您无法检测到该区域的退出和重新进入。我想你可以使用一个非标准的BLE外设来改变它的MAC地址来克服这个问题。该应用程序不能简单地弹出到前台,但可以创建本地通知和其他后台操作。由于iOS打开和关闭扫描以保持电池电量,因此检测可能不会立即进行。

  • iBeacon Ranging will not work directly. iBeacon Monitoring will call didEnterRegion and give the app runtime of 6 seconds - in which you can start Ranging (for example, to detect major & minor). The detection may not be immediate since iOS turns scanning on and off to preserve the battery power. If you enter a region of multiple beacons with the same ProximityUUID, and you monitor this UUID without a specific major and\or minor, didEnterRegion will be called when you start receiving the signal from the first beacon - however, if you did not exit the region of the first beacon and you also entered the region of a second beacon the app will not be woken up again (didEnterRegion will not be called again) so you cannot start ranging to detect the second beacon's major & minor. The app cannot simply pop up to the foreground, but can create local notifications and other background operations.
  • CoreBluetooth - According to Core Bluetooth Background Processing scanForPeripheralsWithServices can run in the background using, but you must specify at least one serviceUUID. didDiscoverPeripheral will be given a runtime of 10 seconds. Using CBCentralManagerScanOptionAllowDuplicatesKey will not work - didDiscoverPeripheral will be called once for every peripheral. Therefore, you cannot detect "exit" from the region and "re-entry". I suppose you can use a non-standard BLE peripheral that changes its MAC address to overcome this issue. The app cannot simply pop up to the foreground, but can create local notifications and other background operations. The detection may not be immediate since iOS turns scanning on and off to preserve the battery power.

在应用程序被杀后运行


  • iBeacon监控 - 工作!即使用户杀死了应用程序或设备已重新启动。

  • CoreBluetooth - 如果应用程序被iOS杀死(由于不活动或内存限制),应用程序将被唤醒。但是,如果用户明确地杀死了应用程序,它将不会被唤醒(这使得第一个案例难以测试)。我不知道设备重启后会发生什么......

有没有人有更多这些限制的经验?可以 scanForPeripheralsWithServices 在某些用例中用作iBeacon Monitoring的更好替代方案吗?

Does anyone have more experience with these restrictions? Can scanForPeripheralsWithServices be used as a better alternative to iBeacon Monitoring in some use-cases?

谢谢!

推荐答案

您的描述大多正确。只需两个澄清:

You are mostly right with your description. Just two clarifications:


  • 每个设备的20个区域限制,它是特定于应用的。无论其他应用在移动设备上做什么,您的应用仍然可以通过iOS监控多达20个地区。也就是说,可能存在硬件限制,这些限制是特定于设备的,可以通过硬件辅助在后台监控多少个区域。这些限制没有记录。如果超过这些未记录的限制,则在后台检测到的信标可能需要更长的时间。 (尽管如此,无论如何都没有操作系统保证检测何时到来。)

  • The 20 region limit is not per device, it is app-specific. No matter what other apps are doing on the mobile device, your app is still allowed to monitor up to 20 regions by iOS. That said, there are likely hardware limits that are device-specific on how many regions can be monitored in the background with hardware assistance. These limits are undocumented. If you surpass these undocumented limits, it will probably take a lot longer to detected beacons in the background. (Although that said, there is no OS guarantee of when the detections come, anyway.)

您无法连接到 CLBeacon 使用监控和范围API。这些API仅适用于无连接的BLE广告包。

You cannot connect to a CLBeacon using Monitoring and Ranging APIs. These APIs only work with BLE advertising packets, which are connectionless.

是的,可以使用 scanForPeripheralsWithServices 作为替代方案。这就是Gimbal信标为实现专有系统所做的事情。然而,在背景检测时间和可靠性方面存在实际缺点。

Yes, it is possible to use scanForPeripheralsWithServices as an alternative. This is what Gimbal beacons do in order to implement a proprietary system. There are real disadvantages, however, in terms of background detection time and reliability.

这篇关于通过iBeacon Monitoring& amp; amp; amp; amp; Ranging vs CoreBluetooth scanForPeripheralsWithServices的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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