Characteristic
public class Characteristic
extension Characteristic: Equatable
Characteristic is a class implementing ReactiveX which wraps CoreBluetooth functions related to interaction with CBCharacteristic
-
Intance of CoreBluetooth characteristic class
Declaration
Swift
public let characteristic: CBCharacteristic -
Service which contains this characteristic
Declaration
Swift
public let service: Service -
Current value of characteristic. If value is not present - it’s
nil.Declaration
Swift
public var value: Data? { get } -
The Bluetooth UUID of the
Characteristicinstance.Declaration
Swift
public var uuid: CBUUID { get } -
Flag which is set to true if characteristic is currently notifying
Declaration
Swift
public var isNotifying: Bool { get } -
Properties of characteristic. For more info about this refer to CBCharacteristicProperties
Declaration
Swift
public var properties: CBCharacteristicProperties { get } -
Value of this property is an array of
Descriptorobjects. They provide more detailed information about characteristics value.Declaration
Swift
public var descriptors: [Descriptor]? { get } -
Function that triggers descriptors discovery for characteristic.
Observable can ends with following errors:
BluetoothError.descriptorsDiscoveryFailedBluetoothError.peripheralDisconnectedBluetoothError.destroyedBluetoothError.bluetoothUnsupportedBluetoothError.bluetoothUnauthorizedBluetoothError.bluetoothPoweredOffBluetoothError.bluetoothInUnknownStateBluetoothError.bluetoothResetting
Declaration
Swift
public func discoverDescriptors() -> Single<[Descriptor]>Return Value
Singlethat emitsnextwith array ofDescriptorinstances, once they’re discovered. -
Function that allow to observe writes that happened for characteristic.
Observable can ends with following errors:
BluetoothError.characteristicWriteFailedBluetoothError.peripheralDisconnectedBluetoothError.destroyedBluetoothError.bluetoothUnsupportedBluetoothError.bluetoothUnauthorizedBluetoothError.bluetoothPoweredOffBluetoothError.bluetoothInUnknownStateBluetoothError.bluetoothResetting
Declaration
Swift
public func observeWrite() -> Observable<Characteristic>Return Value
Observablethat emitsnextwithCharacteristicinstance every time when write has happened. It’s infinite stream, so.completeis never called. -
Function that allows to know the exact time, when isNotyfing value has changed on a characteristic.
Observable can ends with following errors:
BluetoothError.characteristicSetNotifyValueFailedBluetoothError.peripheralDisconnectedBluetoothError.destroyedBluetoothError.bluetoothUnsupportedBluetoothError.bluetoothUnauthorizedBluetoothError.bluetoothPoweredOffBluetoothError.bluetoothInUnknownStateBluetoothError.bluetoothResetting
Declaration
Swift
public func observeNotifyValue() -> Observable<Characteristic>Return Value
ObservableemittingCharacteristicwhen isNoytfing value has changed. -
Function that triggers write of data to characteristic. Write is called after subscribtion to
Observableis made. Behavior of this function strongly depends on CBCharacteristicWriteType, so be sure to check this out before usage of the method.withResponse-ObservableemitsnextwithCharacteristicinstance write was confirmed without any errors. If any problem has happened, errors are emitted.withoutResponse-ObservableemitsnextwithCharacteristicinstance once write was called. Result of this call is not checked, so as a user you are not sure if everything completed successfully. Errors are not emitted
Observable can ends with following errors:
BluetoothError.characteristicWriteFailedBluetoothError.peripheralDisconnectedBluetoothError.destroyedBluetoothError.bluetoothUnsupportedBluetoothError.bluetoothUnauthorizedBluetoothError.bluetoothPoweredOffBluetoothError.bluetoothInUnknownStateBluetoothError.bluetoothResetting
Declaration
Swift
public func writeValue(_ data: Data, type: CBCharacteristicWriteType) -> Single<Characteristic>Parameters
dataDatathat’ll be written to theCharacteristictypeType of write operation. Possible values:
.withResponse,.withoutResponseReturn Value
Singlewhose emission depends onCBCharacteristicWriteTypepassed to the function call. Behavior is following: -
Function that allow to observe value updates for
Characteristicinstance.Observable can ends with following errors:
BluetoothError.characteristicReadFailedBluetoothError.peripheralDisconnectedBluetoothError.destroyedBluetoothError.bluetoothUnsupportedBluetoothError.bluetoothUnauthorizedBluetoothError.bluetoothPoweredOffBluetoothError.bluetoothInUnknownStateBluetoothError.bluetoothResetting
Declaration
Swift
public func observeValueUpdate() -> Observable<Characteristic>Return Value
Observablethat emitsNextwithCharacteristicinstance every time when value has changed. It’s infinite stream, so.completeis never called. -
Function that triggers read of current value of the
Characteristicinstance. Read is called after subscription toObservableis made.Observable can ends with following errors:
BluetoothError.characteristicReadFailedBluetoothError.peripheralDisconnectedBluetoothError.destroyedBluetoothError.bluetoothUnsupportedBluetoothError.bluetoothUnauthorizedBluetoothError.bluetoothPoweredOffBluetoothError.bluetoothInUnknownStateBluetoothError.bluetoothResetting
Declaration
Swift
public func readValue() -> Single<Characteristic>Return Value
Singlewhich emitsnextwith given characteristic when value is ready to read. -
Setup characteristic notification in order to receive callbacks when given characteristic has been changed. Returned observable will emit
Characteristicon every notification change. It is possible to setup more observables for the same characteristic and the lifecycle of the notification will be shared among them.Notification is automaticaly unregistered once this observable is unsubscribed
This is infinite stream of values.
Observable can ends with following errors:
BluetoothError.characteristicReadFailedBluetoothError.peripheralDisconnectedBluetoothError.destroyedBluetoothError.bluetoothUnsupportedBluetoothError.bluetoothUnauthorizedBluetoothError.bluetoothPoweredOffBluetoothError.bluetoothInUnknownStateBluetoothError.bluetoothResetting
Declaration
Swift
public func observeValueUpdateAndSetNotification() -> Observable<Characteristic>Return Value
ObservableemittingnextwithCharacteristicwhen given characteristic has been changed.
View on GitHub
Characteristic Class Reference