0

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.

dickfala
  • 3,246
  • 3
  • 31
  • 52
  • Since you can detect that bluetooth turned off you can ask user navigate to settings to enable it. https://stackoverflow.com/a/5655727/1163224 – ProblemSlover Aug 01 '22 at 09:15
  • I have another situation and application, so I need user turn off the Bluetooth make sure. So I want to check the control panel Bluetooth states. – dickfala Aug 01 '22 at 12:25
  • 1
    You cannot detect the state where Bluetooth is off in the control Center. Attempting to start BLE discovery in that state will result in ios showing a dialog alert to the user butt there is no feedback to your app – Paulw11 Aug 01 '22 at 13:42

0 Answers0