我创建了一个搜索最近的蓝牙设备的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)
}