Assuming you have an iOS5 or iOS6 device and that you have a CBCentralManager object, you can check its CBCentralManagerState with the following:
switch ([_manager state])
{
case CBCentralManagerStateUnsupported:
state = @"This device does not support Bluetooth Low Energy.";
break;
case CBCentralManagerStateUnauthorized:
state = @"This app is not authorized to use Bluetooth Low Energy.";
break;
case CBCentralManagerStatePoweredOff:
state = @"Bluetooth on this device is currently powered off.";
break;
case CBCentralManagerStateResetting:
state = @"The BLE Manager is resetting; a state update is pending.";
break;
case CBCentralManagerStatePoweredOn:
state = @"Bluetooth LE is turned on and ready for communication.";
break;
case CBCentralManagerStateUnknown:
state = @"The state of the BLE Manager is unknown.";
break;
default:
state = @"The state of the BLE Manager is unknown.";
}
You'll want to watch for centralManagerDidUpdateState:central
delegate updates as well, then take the appropriate action in your app.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…