如何解决[CoreBluetooth] API MISUSE:只能在swift 4的开机状态下接受此命令?

时间:2018-03-07 10:41:16

标签: swift xcode swift3 core-bluetooth xcode9-beta

我创建了一个搜索最近的蓝牙设备的iOS应用。 但是,当我在iPhone上运行此应用程序时,会出现以下错误

  

[CoreBluetooth] API MISUSE:只能接受此命令   开启状态

我该怎么做才能解决此错误以及应用中出现此错误的原因? 提前谢谢

func centralManagerDidUpdateState(_ central: CBCentralManager) {
    print(central.state)
    switch (central.state) {
    case CBManagerState.poweredOff:
       print("CoreBluetooth BLE hardware is powered off")
        break;
    case CBManagerState.unauthorized:
        print("CoreBluetooth BLE state is unauthorized")
        break

    case CBManagerState.unknown:
         print("CoreBluetooth BLE state is unknown");
        break

    case CBManagerState.poweredOn:
        print("CoreBluetooth BLE hardware is powered on and ready")
        bluetoothAvailable = true;
        break;

    case CBManagerState.resetting:
         print("CoreBluetooth BLE hardware is resetting")
        break;
    case CBManagerState.unsupported:
          print("CoreBluetooth BLE hardware is unsupported on this platform");
        break
    }
    if bluetoothAvailable == true
    {
        discoverDevices()
    }

}

func discoverDevices() {
    print("Discovering devices")
    manager?.scanForPeripherals(withServices: nil, options: nil)
    //centralManager.scanForPeripheralsWithServices(nil, options: nil)

}

0 个答案:

没有答案