CoreBluetooth CBMutableCharacteristic 属性与权限

CoreBluetooth CBMutableCharacteristic properties vs permissions

我正在更新需要充当蓝牙外围设备的 iOS 应用程序。我一直在引用 Apple 的“Transferring Data Between Bluetooth Low Energy Devices" sample code and I'm confused about the properties vs the permissions of a CBMutableCharacteristic。以下是 Apple 的示例代码如何初始化 CBMutableCharacteristic 的实例:

let transferCharacteristic = CBMutableCharacteristic(type: TransferService.characteristicUUID,
                                                 properties: [.notify, .writeWithoutResponse],
                                                 value: nil,
                                                 permissions: [.readable, .writeable])

权限文档提供了以下解释:

When you initialize a new mutable characteristic, you set the read, write, and encryption permissions for the characteristic’s value. Setting the read and write permissions for a characteristic’s value is different from specifying the read and write properties for a characteristic’s value.

到目前为止,还不错。但这就是我感到困惑的地方:

When you specify the read and write properties, the client (a central) inspects the read and write permissions of the characteristic’s value. When you specify the read and write permissions for a characteristic’s value, you set the permissions for the server (the peripheral) to allow the type of read or write specified by the characteristic’s properties. Therefore, when you initialize a mutable characteristic, you need to specify read or write properties and their corresponding permissions.

我可能已经读了至少十几遍了,但我仍然不确定我是否理解了它!如果有任何核心蓝牙专家可以为我澄清这一点,我将不胜感激!

permissions指定可以做什么到特征-

  • 能写出来吗?
  • 能看懂吗?

properties指定如何完成 -

  • 如果允许写入,可以使用write with response吗? 写入无响应?
  • 如果允许阅读,可以使用notify吗? 表示阅读?

您问题中的示例指定了一个可读可写的特征。

权限:[.readable, .writeable]

读取是通过notify进行的(当值改变时,peripheral通知Central)。

写入没有响应(外设不向中央提供指示写入是否成功的响应)。

属性:[.notify, .writeWithoutResponse]