首页 > 解决方案 > Swift - 无法通过 BLE 读取多个特征

问题描述

我的应用程序能够通过 BLE 成功订阅这两个特征,但它只从其中一个特征中读取数据。以下是我能够成功读取单个特征但不能读取多个特征的代码。

    func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
    
    guard characteristic == rxCharacteristic,
        let data:Data = characteristic.value
        else { return }

    var myFloatArray = Array<Float>(repeating: 0, count: data.count/MemoryLayout<Float>.stride)
    myFloatArray.withUnsafeMutableBytes { data.copyBytes(to: $0) }

标签: swiftbluetooth-lowenergy

解决方案


推荐阅读