Skip to content

2. Manager State

paweljaneczek edited this page Jun 29, 2018 · 2 revisions

Interacting with BLE devices requires specific conditions under which it is possible. To find out what the current state of the Bluetooth Adapter is, the following two functions are available:

let state: BluetoothState = manager.state

The above function returns BluetoothState enum, that corresponds to CBManagerState enum.

All APIs work only when the active state is BluetoothState.poweredOn. The example of observing for that state:

let disposable = manager.observeState()
     .startWith(state)
     .filter { $0 == .poweredOn }
// now you can do next actions on manager e.g. manager.scanForPeripherals(nil)

In order to stop observing state changes dispose observable with:

disposable.dispose()