Hello everyone,
Starting with iOS 11, we're consistently encountering an issue with CBCentralManager where bluetooth antenna seems to be enabled but CBCentralManager actually reports .poweredOff.
Steps to reproduce
- Bluetooth is enabled in both Settings panel and in Control Center. Launching a dummy app that instanciates a CBCentralManager describes it's state as .poweredOn. (let's call this working state)
- Swipe Control Center and disable Bluetooth.
- Without leaving Control Center enable Airplane Mode (this fades all wifi, 3G and Bluetooth icons).
- Again, without leaving Control Center, disable Airplane Mode (this should automatically enable at least Bluetooth).
- Open the same dummy app as in step 1.
Expected result
CBCentralManager should report .poweredOn state.
Observed result
CBCentralManager state is .poweredOff.
Additional observations
This issue has been confirmed on both iPhone 7 running iOS 11.1.1 and iPhone SE running iOS 11.0.3. The behaviour has also been confirmed with other apps like LightBlue.
In another dummy app (let's call it dummyB) that permanently holds a reference to a CBCentralManager instance, if steps 3 and 4 are executed while the app is running, the existing CBCentralManager instance's centralManagerDidUpdateState: callback will report .poweredOff, as stated above. Now, if we disable-enable bluetooth in the system-wide Settings panel, upon returning to dummyB, centralManagerDidUpdateState: will report .poweredOn, but any new fresh instance of CBCentralManager will report .poweredOff state.
Known workarounds
Apparently, the only way to restore a sane Bluetooth stack state is to disable-enable the option in the Control Center (assuming it's already enabled in the Settings panel). From the on, references to CBCentralManager instances both in background running apps and fresh instances report .poweredOn state and connections can successfully be established with peripherals.