LittleBlueTooth

public class LittleBlueTooth : Identifiable

LittleBlueTooth can control only one peripheral at time. It has an id properties to identifiy different instances. Please note that Apple do not enacourage the use of more CBCentralManger instances, due to resurce hits. Link

Public variables

  • id

    LittleBlueTooth instance identifier

    Declaration

    Swift

    public let id: UUID
  • This is usefull when you have auto-reconnection and want to do some task right after a connection. All other tasks will be delayed until this one ends.

    Declaration

    Swift

    public var connectionTasks: AnyPublisher<Void, LittleBluetoothError>?
  • This handler must be used to handle connection process after a disconnession. You can inspect the error and decide if an automatic connection is necessary. If you return true the connection process will start, once the peripheral has been found a connection will be established. If you return false iOS will not try to establish a connection Connection process will remain active also in background if the app has the right permission, to cancel just call disconnect. When a connection will be established an .autoConnected(PeripheralIdentifier) event will be streamed to the connectionEventPublisher

    Declaration

    Swift

    public var autoconnectionHandler: AutoconnectionHandler?
  • Connected peripheral. nil if not connected or a connection is not requested

    Declaration

    Swift

    public var peripheral: Peripheral? { get set }
  • Publisher that streams peripheral state available only when a connection is requested for fine grained control

    Declaration

    Swift

    public var peripheralStatePublisher: AnyPublisher<PeripheralState, Never> { get }
  • Publisher that streams ConnectionEvent

    Declaration

    Swift

    public lazy var connectionEventPublisher: AnyPublisher<ConnectionEvent, Never> { get set }
  • Publish name and service changes

    Declaration

    Swift

    public var changesStatePublisher: AnyPublisher<PeripheralChanges, Never> { get }
  • Publish all values from LittleBlueToothCharacteristic that you are already listening to. It’s up to you to filter them and convert raw data to the Readable object.

    Declaration

    Swift

    public var listenPublisher: AnyPublisher<LittleBlueToothCharacteristic, LittleBluetoothError> { get }
  • Undocumented

    Declaration

    Swift

    public var restoreStatePublisher: AnyPublisher<CentralRestorer, Never> { get }
  • Enable logging disabled by default Enable logging, log is made using os_log and it exposes some information even in release configuration

    Declaration

    Swift

    public var isLogEnabled: Bool { get set }

Init

RSSI

Listen

Read

  • Read a value from a specific charteristic

    Important

    The type of the value must be conform to Readable

    Declaration

    Swift

    public func read<T>(from characteristic: LittleBlueToothCharacteristic) -> AnyPublisher<T, LittleBluetoothError> where T : Readable

    Parameters

    characteristic

    characteristic where you want to read

    Return Value

    A publisher with the value you want to read.

Write

  • Write a value to a specific charteristic

    Important

    The type of the value must be conform to Writable

    Declaration

    Swift

    public func write<T>(to characteristic: LittleBlueToothCharacteristic, value: T, response: Bool = true) -> AnyPublisher<Void, LittleBluetoothError> where T : Writable

    Parameters

    characteristic

    characteristic where you want to write

    value

    The value you want to write

    response

    An optional Bool value that will look for error after write operation

    Return Value

    A publisher with that informs you about eventual error

  • Write a value to a specific charteristic and wait for a response

    Important

    Written value must conform to Writable, response must conform to Readable

    Declaration

    Swift

    public func writeAndListen<W, R>(from characteristic: LittleBlueToothCharacteristic, value: W) -> AnyPublisher<R, LittleBluetoothError> where W : Writable, R : Readable

    Parameters

    characteristic

    characteristic where you want to write and listen

    value

    The value you want to write must conform to Writable

    Return Value

    A publisher with that post and error or the response of the write requests.

Discover

Connect

Disconnect

Extraction and restart