I'm in the process of updating an iOS app that needs to act as a Bluetooth peripheral. I've been referencing Apple's "Transferring Data Between Bluetooth Low Energy Devices" sample code and I'm confused about the properties vs the permissions of a CBMutableCharacteristic. Here's how Apple's sample code inits an instance of CBMutableCharacteristic:
let transferCharacteristic = CBMutableCharacteristic(type: TransferService.characteristicUUID,
properties: [.notify, .writeWithoutResponse],
value: nil,
permissions: [.readable, .writeable])
The docs for permissions offer the following explanation:
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.
So far, so good. But here's where I'm getting confused:
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.
I've probably read that at least a dozen times and I'm still not sure that I understand it! If there are any Core Bluetooth experts out there who can clarify this for me, I'd certainly appreciate it!
The permissions
specify what can be done to the characteristic -
The properties
specify how it can be done -
The example in your question specifies a characteristic that is both readable and writable.
Permissions: [.readable, .writeable]
Reads are performed via notify (The peripheral notifies the Central when the value changes).
Writes are performed without a response (The peripheral does not provide a response to the central indicating whether the write was successful or not).
Properties: [.notify, .writeWithoutResponse]