我有一个在后台使用长期BLE扫描的应用程序。我想检测蓝牙何时关闭,以便可以向用户发送通知,告知应用程序功能将受到限制。这可能吗?
答案 0 :(得分:2)
您可以遵循CBCentralManagerDelegate
并实现centralManagerDidUpdateState(_:)
来通知状态更改
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")
}
}
希望这会有所帮助