I am using the centralManagerDidUpdateState in my code.
I can check the bluetooth ON/Off in programming like below:
@interface ViewController ()<CBCentralManagerDelegate,CBPeripheralManagerDelegate>
{
CBCentralManager *bleCentralManager;
CBPeripheralManager *blePeripheralManager;
}
@end
- (void)viewDidLoad {
[super viewDidLoad];
bleCentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:@{CBCentralManagerOptionShowPowerAlertKey: @NO}];
blePeripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil options:@{CBConnectPeripheralOptionNotifyOnDisconnectionKey:@YES}];
bleStatus = @"CBManagerStateUnknown";
}
-(void) centralManagerDidUpdateState:(CBCentralManager *)central{
NSLog(@"centralManagerDidUpdateState:%ld",central.state);
switch (central.state) {
case CBManagerStateUnknown:
bleStatus = @"CBManagerStateUnknown";
break;
case CBManagerStateResetting:
bleStatus = @"CBManagerStateResetting";
break;
case CBManagerStateUnsupported:
bleStatus = @"CBManagerStateUnsupported";
break;
case CBManagerStateUnauthorized:
bleStatus = @"CBManagerStateUnauthorized";
break;
case CBManagerStatePoweredOff:
bleStatus = @"CBManagerStatePoweredOff";
break;
case CBManagerStatePoweredOn:
bleStatus = @"CBManagerStatePoweredOn";
break;
default:
break;
}
}
- (void)peripheralManagerDidUpdateState:(nonnull CBPeripheralManager *)peripheral {
NSLog(@"peripheral:%ld",(long)peripheral.state);
}
But in the iPhone control center, we can change the bluetooth status to disconnect, the turn off status is can't recognition.
When the bluetooth icon disconnect and bluetooth(go to setting) turn off, I get the status is CBManagerStaePoweredOff.
We can refer the disconnect/off info in control panel below: https://support.apple.com/en-us/HT208086
How can I check the status is Disconnect from Bluetooth icon or Turn off bluetooth(go to setting bluetooth edit turn off) in the control panel icon?
thank you very much.