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
Characteristic
instance.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
Descriptor
objects. 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.descriptorsDiscoveryFailed
BluetoothError.peripheralDisconnected
BluetoothError.destroyed
BluetoothError.bluetoothUnsupported
BluetoothError.bluetoothUnauthorized
BluetoothError.bluetoothPoweredOff
BluetoothError.bluetoothInUnknownState
BluetoothError.bluetoothResetting
Declaration
Swift
public func discoverDescriptors() -> Single<[Descriptor]>
Return Value
Single
that emitsnext
with array ofDescriptor
instances, once they’re discovered. -
Function that allow to observe writes that happened for characteristic.
Observable can ends with following errors:
BluetoothError.characteristicWriteFailed
BluetoothError.peripheralDisconnected
BluetoothError.destroyed
BluetoothError.bluetoothUnsupported
BluetoothError.bluetoothUnauthorized
BluetoothError.bluetoothPoweredOff
BluetoothError.bluetoothInUnknownState
BluetoothError.bluetoothResetting
Declaration
Swift
public func observeWrite() -> Observable<Characteristic>
Return Value
Observable
that emitsnext
withCharacteristic
instance every time when write has happened. It’s infinite stream, so.complete
is 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.characteristicSetNotifyValueFailed
BluetoothError.peripheralDisconnected
BluetoothError.destroyed
BluetoothError.bluetoothUnsupported
BluetoothError.bluetoothUnauthorized
BluetoothError.bluetoothPoweredOff
BluetoothError.bluetoothInUnknownState
BluetoothError.bluetoothResetting
Declaration
Swift
public func observeNotifyValue() -> Observable<Characteristic>
Return Value
Observable
emittingCharacteristic
when isNoytfing value has changed. -
Function that triggers write of data to characteristic. Write is called after subscribtion to
Observable
is made. Behavior of this function strongly depends on CBCharacteristicWriteType, so be sure to check this out before usage of the method.withResponse
-Observable
emitsnext
withCharacteristic
instance write was confirmed without any errors. If any problem has happened, errors are emitted.withoutResponse
-Observable
emitsnext
withCharacteristic
instance 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.characteristicWriteFailed
BluetoothError.peripheralDisconnected
BluetoothError.destroyed
BluetoothError.bluetoothUnsupported
BluetoothError.bluetoothUnauthorized
BluetoothError.bluetoothPoweredOff
BluetoothError.bluetoothInUnknownState
BluetoothError.bluetoothResetting
Declaration
Swift
public func writeValue(_ data: Data, type: CBCharacteristicWriteType) -> Single<Characteristic>
Parameters
data
Data
that’ll be written to theCharacteristic
type
Type of write operation. Possible values:
.withResponse
,.withoutResponse
Return Value
Single
whose emission depends onCBCharacteristicWriteType
passed to the function call. Behavior is following: -
Function that allow to observe value updates for
Characteristic
instance.Observable can ends with following errors:
BluetoothError.characteristicReadFailed
BluetoothError.peripheralDisconnected
BluetoothError.destroyed
BluetoothError.bluetoothUnsupported
BluetoothError.bluetoothUnauthorized
BluetoothError.bluetoothPoweredOff
BluetoothError.bluetoothInUnknownState
BluetoothError.bluetoothResetting
Declaration
Swift
public func observeValueUpdate() -> Observable<Characteristic>
Return Value
Observable
that emitsNext
withCharacteristic
instance every time when value has changed. It’s infinite stream, so.complete
is never called. -
Function that triggers read of current value of the
Characteristic
instance. Read is called after subscription toObservable
is made.Observable can ends with following errors:
BluetoothError.characteristicReadFailed
BluetoothError.peripheralDisconnected
BluetoothError.destroyed
BluetoothError.bluetoothUnsupported
BluetoothError.bluetoothUnauthorized
BluetoothError.bluetoothPoweredOff
BluetoothError.bluetoothInUnknownState
BluetoothError.bluetoothResetting
Declaration
Swift
public func readValue() -> Single<Characteristic>
Return Value
Single
which emitsnext
with 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
Characteristic
on 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.characteristicReadFailed
BluetoothError.peripheralDisconnected
BluetoothError.destroyed
BluetoothError.bluetoothUnsupported
BluetoothError.bluetoothUnauthorized
BluetoothError.bluetoothPoweredOff
BluetoothError.bluetoothInUnknownState
BluetoothError.bluetoothResetting
Declaration
Swift
public func observeValueUpdateAndSetNotification() -> Observable<Characteristic>
Return Value
Observable
emittingnext
withCharacteristic
when given characteristic has been changed.