Why do I get CBCentralManagerStateUnknown
on an iPad 2 when using this simple code?
- (BOOL)viewDidLoad {
bluetoothManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
if ([manager state] == CBCentralManagerStatePoweredOff) NSLog(@"CBCentralManagerStatePoweredOff");
if ([manager state] == CBCentralManagerStatePoweredOn) NSLog(@"CBCentralManagerStatePoweredOn");
if ([manager state] == CBCentralManagerStateResetting) NSLog(@"CBCentralManagerStateResetting");
if ([manager state] == CBCentralManagerStateUnauthorized) NSLog(@"CBCentralManagerStateUnauthorized");
if ([manager state] == CBCentralManagerStateUnknown) NSLog(@"CBCentralManagerStateUnknown");
if ([manager state] == CBCentralManagerStateUnsupported) NSLog(@"CBCentralManagerStateUnsupported");
}
I cannot figure out what CBCentralManagerStateUnknown
means. What do I do? The Apple docs just say:
State unknown, update imminent.
I get this response with a Bluetooth device connected, and also when Bluetooth is off.
If I try to run something like [manager retrieveConnectedPeripherals]
, I also get this message in the console:
CoreBluetooth[WARNING] <CBConcreteCentralManager: ...> is not powered on
I know why delegate is never called. Because the object is deleted from memory. Just make a strong property
@property (strong, nonatomic) DiscoverBluetoothDevices *btDevices;
And in init
@implementation DiscoverBluetoothDevices
- (id) init
{
self = [super init];
if(self) {
centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
[centralManager scanForPeripheralsWithServices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey: @YES}];
}
return self;
}
And now delegate is called properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With