I am working on a BLE project, for that I initiate CBCentralManager, and scan for available devices. I am able to scan and connect with available BLE peripheral device.
Everything is working fine till I have not tested this on iOS 11.0.x version.
when I tested on iOS 11.1.1 or 11.1.2, CBCentralManager always return me poweredOff state, when launch app. But when I open control center, and turn off and turn on bluetooth again or activate/deactivate FlightMode (automatically turn off/on bluetooth). App start scanning BLE peripherals and everything looks fine, till restart on app.
Does anyone faced such issue on iOS 11.1.x and able to fix this,Please help to fix this.
Below is my code to check status
func initiateCentralManager(){
manager = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionRestoreIdentifierKey : "MyBLECurrentState"])
}
func centralManagerDidUpdateState(_ central: CBCentralManager){
print("Received CBCentralManager state")
peripheralArray.removeAll()
if central.state == .poweredOn {
print("poweredOn")
} else if central.state == .poweredOff {
print("poweredOff")
}
}
Here is what is happening
iOS has 3 levels of Bluetooth status:
CBCentralManager
will return poweredOff
state on cases 2
and 3
To be in state 1
(Bluetooth ON and New Connections Allowed)
OFF
Bluetooth in settingsON
in Control CenterTo be in state 2
(Bluetooth ON and New
Connections Not Allowed)
OFF
Bluetooth in settingsON
in Control CenterOFF
in Control Center (the button will change to white)To go in state 1
from 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With