【问题标题】:Get uuid in didreceivewriterequests ios在 didreceivewriterequests ios 中获取 uuid
【发布时间】:2017-08-25 23:41:19
【问题描述】:

我正在使用 ble 在 tizen 和 ios 之间进行 BLE trnasport。我可以发送和接收数据,但我想添加一些逻辑。 IOS 函数,在 ios 接收数据时调用 didreceivewriterequests() 回调,我想将接收到的数据存储到带有 uuid 的列表中。 Tizen 已经有了这个逻辑。但我不知道如何让 uuid 识别 uuid 包含的数据。我想通过 uuid 的列表获取其他功能中的数据。
如何在 didreceivewriterequests() 回调中获取 uuid? 谢谢。

  • 如我所见,CBATTRequest.characteristic.UUID 已被弃用。

【问题讨论】:

    标签: ios bluetooth bluetooth-lowenergy uuid


    【解决方案1】:

    characteristic.uuid 未被弃用。您需要从 requests 数组中的每个请求访问它。从那里您可以检索特征的UUID

    func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) {
        for request in requests {
            let id = request.characteristic.uuid
            print("ID is \(id.uuidString)")
        }
    }
    

    【讨论】:

    • 在我提问之前我参考了stackoverflow.com/questions/27193041/…。但我也看到developer.apple.com/library/content/releasenotes/General/…。它也显示“已删除 CBCharacteristic.UUID”和stackoverflow.com/questions/26169472/…
    • 如果您将我的代码复制并粘贴到您的项目中并运行它,会发生什么?
    • UUID 已从 CBCharacteristic 中删除,因为它已移至超类 CBAttribute;所以它仍然可用,因为它没有在该类中被弃用 - developer.apple.com/documentation/corebluetooth/cbattribute
    • 比,我怎样才能得到 uuid? CBATTRequest* 请求; request.characteristic.uuid show 'property 'uuid' not found on type of 'CBCharacteristic *'.
    • 哦,我可以得到特征的 uuid,但我想得到服务的 uuid。当我使用 CBMutableService alloc 连接到远程设备时...据我所知,有 2 个 UUID。一种是服务uuid​​,一种是特征uuid。要连接远程设备,扫描服务 uuid 和搜索特征 uuid。是否可以在回调函数中找到服务uuid​​?
    【解决方案2】:

    斯威夫特 3

      func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) {
    
         for writeRequest in requests {
    
            print(characteristic.uuid.uuidString)
         }
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-19
      • 1970-01-01
      • 2017-08-28
      • 1970-01-01
      • 2023-02-09
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多