使用 iOS 获取低功耗蓝牙扫描响应数据 [英] Obtaining Bluetooth LE scan response data with iOS

查看:60
本文介绍了使用 iOS 获取低功耗蓝牙扫描响应数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用低功耗蓝牙设备,我想知道是否可以在不连接的情况下使用 iOS 和 Core 蓝牙读取广告的扫描响应数据.

I am working with Bluetooth Low Energy devices, and I was wondering whether it is possible to read the Scan Response Data to an advertisement with iOS and Core Bluetooth without connecting.

据我所知,在读取广告数据包后,您可以以 31 字节扫描响应的格式向外设请求附加数据.我知道Core Bluetooth 建议,如果广告包已满,您可以将本地名称放在扫描响应包中,但是它可以让您看到整个包吗?

I understand that after reading an advertisement packet, you can request additional data from the peripheral in the format of a 31 byte scan response. I know that Core Bluetooth suggests that if the ad packet is full, you can put the local name in the scan response packet, but does it allow you to see the whole packet?

推荐答案

是的,您可以使用 CoreBluetooth 读取 BLE 广告的完整制造商数据或服务数据字节它不是 iBeacon 广告. 如果是 iBeacon 广告,CoreBluetooth 将阻止您查看字节.你使用的回调如下:

Yes, you can use CoreBluetooth to read the full manufacturer data or service data bytes of a BLE advertisement as long as it is NOT an iBeacon advertisement. If it is an iBeacon advertisement, CoreBluetooth will block your ability to see the bytes. The callback you use is as follows:

- (void)   centralManager:(CBCentralManager *)central
didDiscoverPeripheral:(CBPeripheral *)peripheral
    advertisementData:(NSDictionary *)advertisementData
                 RSSI:(NSNumber *)RSSI

原始服务数据或制造商数据字节将出现在 NSDictionary *advertisementData 中.但是它们持有这些数据的密钥将被 iBeacons 的操作系统删除.

The raw service data or manufacturer data bytes will be present inside the NSDictionary *advertisementData. But they key holding those data will be removed by the operating system for iBeacons.

以下是您在回调中的广告数据 NSDictionary 中获得的示例.此示例用于检测 AltBeacon 广告(开源信标标准),标识符为 2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6 1 2

Here's an example of what you get in the advertisementData NSDictionary in the callback. This example is for detecting an AltBeacon advertisement (an open-source beacon standard), with identifiers 2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6 1 2

{
    kCBAdvDataIsConnectable = 0;
    kCBAdvDataManufacturerData = <1801beac 2f234454 cf6d4a0f adf2f491 1ba9ffa6 00010002 be00>;
}

您可以通过查看 AltBeacon 规范此处了解如何解码上述字节.

You can see how to decode the above bytes by looking at the AltBeacon spec here.

有关为什么无法读取 iBeacon 数据的更多详细信息以及显示如何设置的附加代码,请参见此处:

For more details about why you can't read iBeacon data along with additional code showing how you set this up, see here:

http://developer.radiusnetworks.com/2013/10/21/corebluetooth-doesnt-let-you-see-ibeacons.html

这篇关于使用 iOS 获取低功耗蓝牙扫描响应数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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