Instance Method

writeValue(_:for:type:)

Writes the value of a characteristic.

Declaration

func writeValue(_ data: Data, for characteristic: CBCharacteristic, type: CBCharacteristicWriteType)

Parameters

data

The value to be written.

characteristic

The characteristic whose value is to be written.

type

The type of write to be executed. For a list of the possible types of writes to a characteristic’s value, see CBCharacteristicWriteType.

Discussion

When you call this method to write the value of a characteristic, the peripheral calls the peripheral:didWriteValueForCharacteristic:error: method of its delegate object only if you specified the write type as CBCharacteristicWriteType.withResponse. The response you receive through the peripheral:didWriteValueForCharacteristic:error: delegate method indicates whether the write was successful; if the write failed, it details the cause of the failure in an error. If you specify the write type as CBCharacteristicWriteType.withoutResponse, the write is best-effort and not guaranteed. If the write does not succeed in this case, you are not notified nor do you receive an error indicating the cause of the failure. The data passed into the data parameter is copied, and you can dispose of it after the method returns.

Characteristics may allow only certain type of writes to be performed on their value. To determine which types of writes are permitted to a characteristic’s value, you access the relevant properties of the CBCharacteristicProperties enumeration, which are detailed in CBCharacteristic.

See Also

Writing Characteristic and Characteristic Descriptor Values

func writeValue(Data, for: CBDescriptor)

Writes the value of a characteristic descriptor.