Skip to content

9. Other functionalities

paweljaneczek edited this page Jul 2, 2018 · 2 revisions

Here you'll find some other useful functionalities of the library

Monitor connection state of Peripheral

Property isConnected on Peripheral allows checking if Peripheral is connected. To monitor Peripheral connection state changes use:

peripheral.observeConnection()

It emits new element after connection state changes.

Retrieving Peripherals

CentralManager also lets to retrieve peripherals in two ways:

  • via its identifier using array of UUID objects:
manager.retrieveConnectedPeripherals(withServices: services)
  • connected ones via services identifiers using array of CBUUID objects:
manager.retrievePeripherals(withIdentifiers: identifiers)

In both cases, return type is [Peripheral].

Read RSSI

Triggers read of Peripheral RSSI value. To do it, call readRSSI() on Peripheral instance:

peripheral.readRSSI()

Method returns Single<(Peripheral, Int)>. Peripheral is returned in order to enable chaining.

Monitor services modification

When you want to know, when services are modified, do:

let observable: Observable<(Peripheral, [Service])> = peripheral.observeServicesModification() 

Next event is generated each time, when service changes.

Monitor name update

Call observeNameUpdate() -> Observable<(Peripheral, String?)> in order to know, when peripheral changes its name:

Monitoring write

By calling observeWrite(for characteristic: Characteristic) -> Observable<Characteristic> you're able to receive event each time, when value is being written to characteristic.