Reputation: 235
I created one iOS app which search nearest bluetooth device. But when I run this app on iPhone then below error occure
[CoreBluetooth] API MISUSE: can only accept this command while in the powered on state
What can I do to solve this error and why this error occurs in the app? thanks in advance
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)
}
Upvotes: 6
Views: 7961