I implemented the centralManagerDidUpdateState
function which somehow does not fire the CBCentralManagerStateUnauthorized
state. If I switch off the Bluetooth Sharing option for the App in Settings, it still shows CBCentralManagerStatePoweredOn
state after restarting the App. If I switch the BT Sharing Setting OFF or ON, when the App is running in the background, it even crashes the App with an error which I can't debug. (-> SIGKILL). All delegates are set correctly...
Does anyone know why it crashes and why the function does not detect the Settings correctly?
This is the code:
- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
switch (central.state) {
case CBCentralManagerStatePoweredOff: {
NSLog(@"CoreBluetooth BLE hardware is powered off");
[[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"OFF"];
[[NSUserDefaults standardUserDefaults] setObject:@"OFF" forKey:@"beaconPowerStatus"];
break;
}
case CBCentralManagerStatePoweredOn: {
NSLog(@"CoreBluetooth BLE hardware is powered on and ready");
[[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"ON"];
[[NSUserDefaults standardUserDefaults] setObject:@"ON" forKey:@"beaconPowerStatus"];
break;
}
case CBCentralManagerStateResetting: {
NSLog(@"CoreBluetooth BLE hardware is resetting");
[[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"RESETTING"];
[[NSUserDefaults standardUserDefaults] setObject:@"RESETTING" forKey:@"beaconPowerStatus"];
break;
}
case CBCentralManagerStateUnauthorized: {
NSLog(@"CoreBluetooth BLE state is unauthorized");
[[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"UNAUTHORIZED"];
[[NSUserDefaults standardUserDefaults] setObject:@"UNAUTHORIZED" forKey:@"beaconPowerStatus"];
break;
}
case CBCentralManagerStateUnknown: {
NSLog(@"CoreBluetooth BLE state is unknown");
[[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"UNKNOWN"];
[[NSUserDefaults standardUserDefaults] setObject:@"UNKNOWN" forKey:@"beaconPowerStatus"];
break;
}
case CBCentralManagerStateUnsupported: {
NSLog(@"CoreBluetooth BLE hardware is unsupported on this platform");
[[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"UNSUPPORTED"];
[[NSUserDefaults standardUserDefaults] setObject:@"UNSUPPORTED" forKey:@"beaconPowerStatus"];
break;
}
default:
break;
}
[[NSUserDefaults standardUserDefaults] synchronize];
}