繁体   English   中英

iOS Swift:无法读取 iBeacon 制造商数据(原始数据 Android 等效)

[英]iOS Swift: Can't read iBeacon manufacturer data (raw data Android equivalent)

我正在使用这个 iBeacon BLE 设备https://www.beaconzone.co.uk/LC01BodyTemperature并尝试读取其温度数据。

I've successfully managed to do it in Android Kotlin using RxAndroidBle by accessing ScanResult.scanRecord.bytes and now I'm trying to do the same thing in iOS Swift using RxBluetoothKit by reading ScannedPeripheral.advertisementData.manufacturerData .

根据我对文档的理解,该字段应该是等效于bytes字段的 Android 但在每次测试中我总是返回nil 我还尝试通过访问广告数据中的 CBAdvertisementDataManufacturerDataKey 在centralManager(_:didDiscover:advertisementData:rssi:) advertisementData CBAdvertisementDataManufacturerDataKey本地访问它,但这也返回了nil

我需要从 iBeacon 的原始数据中获取的字节在 position 45(温度的整数部分)和 46(温度的小数部分)中,但我没有得到任何在advertisementData centralManager(_:didDiscover:advertisementData:rssi:)具有设备手册建议的长度的centralManager(_:didDiscover:advertisementData:rssi:)

你对我做错了什么有什么建议吗?

您无法使用CoreBluetooth (这是 RxBluetoothKit 在后台使用的)访问 iBeacon 广告数据

iOS 使用CoreLocation API与 iBeacon 连接。

如果您想使用 iBeacons 并宣传一些数据,您有两种选择:

  1. 您可以将温度数据编码到 iBeacon 广告的主要或次要中,并使用CoreLocation API
  2. 您可以在广告中宣传服务数据类型——然后您可以使用CoreBluetooth访问该数据(因为 iBeacon 广告被 CoreBluetooth 中的CoreBluetooth剥离)。 蓝牙网站
数据类型值 数据类型名称 定义参考
0x16 «服务数据» 蓝牙核心规格:卷。 3,零件 C,第 11.1.10 和 18.10 节 (v4.0)
0x20 «服务数据 - 32 位 UUID» 核心规范补充,A 部分,第 1.11 节
0x21 «服务数据 - 128 位 UUID» 核心规范补充,A 部分,第 1.11 节

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM