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()
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.