【问题标题】:iOS Swift: Can't read iBeacon manufacturer data (raw data Android equivalent)iOS Swift:无法读取 iBeacon 制造商数据(原始数据 Android 等效)
【发布时间】:2021-03-22 16:49:08
【问题描述】:

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

通过访问ScanResult.scanRecord.bytes,我已经成功地在Android Kotlin 中使用RxAndroidBle 做到了这一点,现在我尝试通过阅读ScannedPeripheral.advertisementData.manufacturerData 在iOS Swift 中使用RxBluetoothKit 做同样的事情。

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

我需要从 iBeacon 的原始数据中获取的字节位于位置 45(温度的整数部分)和 46(温度的小数部分),但我没有得到任何在 @ 的 advertisementData 中传输的字节数组987654333@,长度由设备说明书建议。

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

【问题讨论】:

  • CBCentralManager 的扫描选项是什么?您的设备可能会在centralManager(_:didDiscover:advertisementData:rssi:) 中出现多次,事情就是这样,它可能会逐个出现,有时没有名称,然后有名称等,即检查直到有广告数据?
  • @Larme 我使用此选项let options = [ CBCentralManagerOptionRestoreIdentifierKey: "RestoreIdentifierKey", CBCentralManagerScanOptionAllowDuplicatesKey: true ] as [String: AnyObject],是的,它会逐个显示,但我正在寻找的信息不存在。
  • 如果你使用LightBlue.app,广告会出现在那里吗?
  • @Larme 它只显示服务数据,不包含我需要的信息,它不显示制造商数据...

标签: ios swift ibeacon rxandroidble ios-bluetooth


【解决方案1】:

You cannot access iBeacon advertisement data using CoreBluetooth(这是 RxBluetoothKit 在后台使用的)。

iOS 使用CoreLocation API 与 iBeacons 交互。

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

  1. 您可以将温度数据编码到 iBeacon 广告的主要或次要中,并使用CoreLocation API
  2. 您可以在广告中宣传服务数据类型 — 然后您可以使用 CoreBluetooth 访问该数据(因为 iOS 在 CoreBluetooth 中剥离了 iBeacon 广告)。来自Bluetooth website
data type value data type name reference for definition
0x16 «Service Data» Bluetooth Core Specification:Vol. 3, Part C, sections 11.1.10 and 18.10 (v4.0)
0x20 «Service Data - 32-bit UUID» Core Specification Supplement, Part A, section 1.11
0x21 «Service Data - 128-bit UUID» Core Specification Supplement, Part A, section 1.11

【讨论】:

  • CoreLocation API 不只是告诉我与传感器的距离吗?我找不到可以传输我在文档中搜索的数据的方法。你能指点我吗?
  • 我已经编辑了答案。您无法从 CoreLocation 获取其他数据,但您可以在其中对数据进行编码。或者您可以使用不同的广告数据。
猜你喜欢
  • 1970-01-01
  • 2011-05-14
  • 2020-12-14
  • 2018-12-24
  • 2020-10-23
  • 2018-09-07
  • 1970-01-01
  • 2021-02-17
  • 1970-01-01
相关资源
最近更新 更多