I have an app that uses long-term BLE scanning in the background. I would like to detect when Bluetooth has been turned off so that I can send the user a notification saying that the apps functionality will be limited. Is this possible?
You can conform to CBCentralManagerDelegate
and implement centralManagerDidUpdateState(_:)
to be notified of the change in state
func centralManagerDidUpdateState(_ central: CBCentralManager) {
switch central.state {
case .poweredOn:
debugPrint("Scanner powered on")
break
case .poweredOff:
debugPrint("Scanner powered off")
break
case .resetting:
debugPrint("Resetting scanner")
break
case .unauthorized:
debugPrint("Unauthorized")
case .unknown:
debugPrint("unknown")
case .unsupported:
debugPrint("Scanner not supported")
}
}
Hope this helps