通知iOS用户必须打开蓝牙

时间:2018-07-26 16:19:32

标签: ios core-bluetooth

我有一个在后台使用长期BLE扫描的应用程序。我想检测蓝牙何时关闭,以便可以向用户发送通知,告知应用程序功能将受到限制。这可能吗?

1 个答案:

答案 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")
        }
}

希望这会有所帮助