Characteristic

public class Characteristic

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?
  • The Bluetooth UUID of the Characteristic instance.

    Declaration

    Swift

    public var uuid: CBUUID
  • Flag which is set to true if characteristic is currently notifying

    Declaration

    Swift

    public var isNotifying: Bool
  • Properties of characteristic. For more info about this refer to CBCharacteristicProperties

    Declaration

    Swift

    public var properties: CBCharacteristicProperties
  • Value of this property is an array of Descriptor objects. They provide more detailed information about characteristics value.

    Declaration

    Swift

    public var descriptors: [Descriptor]?
  • Function that triggers descriptors discovery for characteristic.

    Declaration

    Swift

    public func discoverDescriptors() -> Single<[Descriptor]>

    Return Value

    Single that emits next with array of Descriptor instances, once they’re discovered.

  • Function that allow to observe writes that happened for characteristic.

    Declaration

    Swift

    public func observeWrite() -> Observable<Characteristic>

    Return Value

    Observable that emits next with Characteristic instance every time when write has happened. It’s infinite stream, so .complete is never called.

  • 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 emits next with Characteristic instance write was confirmed without any errors. If any problem has happened, errors are emitted.

    • withoutResponse - Observable emits next with Characteristic 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

    Declaration

    Swift

    public func writeValue(_ data: Data, type: CBCharacteristicWriteType) -> Single<Characteristic>

    Parameters

    data

    Data that’ll be written to the Characteristic

    type

    Type of write operation. Possible values: .withResponse, .withoutResponse

    Return Value

    Single whose emission depends on CBCharacteristicWriteType passed to the function call. Behavior is following:

  • Function that allow to observe value updates for Characteristic instance.

    Declaration

    Swift

    public func observeValueUpdate() -> Observable<Characteristic>

    Return Value

    Observable that emits Next with Characteristic 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 to Observable is made.

    Declaration

    Swift

    public func readValue() -> Single<Characteristic>

    Return Value

    Single which emits next 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.

    Declaration

    Swift

    public func observeValueUpdateAndSetNotification() -> Observable<Characteristic>

    Return Value

    Observable emitting next with Characteristic when given characteristic has been changed.