小编cjb*_*tin的帖子

CBCentralManager iOS10和iOS9

所以我正在迁移到iOS10,但我还需要我的代码才能在iOS9上运行.我正在使用CoreBluetooth和CBCentralManagerDelegate.我可以让我的代码适用于iOS10但是我需要后备才能适用于iOS9.

func centralManagerDidUpdateState(_ central: CBCentralManager) {
    if #available(iOS 10.0, *) {
        switch central.state{
        case CBManagerState.unauthorized:
            print("This app is not authorised to use Bluetooth low energy")
        case CBManagerState.poweredOff:
            print("Bluetooth is currently powered off.")
        case CBManagerState.poweredOn:
            print("Bluetooth is currently powered on and available to use.")
        default:break
        }
    } else {

        // Fallback on earlier versions
        switch central.state{
        case CBCentralManagerState.unauthorized:
            print("This app is not authorised to use Bluetooth low energy")
        case CBCentralManagerState.poweredOff:
            print("Bluetooth is currently powered off.")
        case CBCentralManagerState.poweredOn:
            print("Bluetooth is currently powered …
Run Code Online (Sandbox Code Playgroud)

ios core-bluetooth swift ios9 ios10

9
推荐指数
3
解决办法
5577
查看次数

标签 统计

core-bluetooth ×1

ios ×1

ios10 ×1

ios9 ×1

swift ×1