ios - 使用 iOS 获取蓝牙 LE 扫描响应数据

标签 ios bluetooth bluetooth-lowenergy core-bluetooth ibeacon

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

据我所知,在读取广告数据包后,您可以以 31 字节扫描响应的格式向外设请求额外的数据。我知道Core Bluetooth建议如果广告包满了,可以把local name放到扫描响应包里,但是这样可以让你看到整个包吗?

最佳答案

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

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

原始服务数据或制造商数据字节将出现在 NSDictionary *advertisementData 中。但是他们保存这些数据的 key 将被 iBeacon 的操作系统删除。

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

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

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

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

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

关于ios - 使用 iOS 获取蓝牙 LE 扫描响应数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25390484/

相关文章:

ios - 如何解决这个错误? - 类 'ViewController' 没有初始化器

ios - GPUImage 创建一个自定义过滤器来更改选定的颜色

node.js - 蓝牙 GATT 数据在飞行中损坏

ios - iPhone BLE/GATT 接口(interface)

android - Android 上如何覆盖 Minor/Major/txPower 等 iBeacon 属性?

ios - 如何将基于 NIB 的项目转换为基于 Storyboard 的项目?

ios - 单元格中的图像显示在 textLabel 和 detailTextLabel 上方,但在附件 View 下方

java - Android 蓝牙套接字卡住应用程序

android - 如何在android中更改蓝牙适配器的扫描模式?

android - 授予应用程序root权限