Why do I get CBCentralManagerStateUnknown
on an iPad 2 when using this simple code?
- (BOOL)viewDidLoad {
bluetoothManager = [[CBCentralManager
CBCentralManagerStateUnknown
simply means iOS has started the BLE process, but has not completed initialization. Give it a moment, and the state will change.
In general, you will "give it a moment" by detecting a state chang in a CBCentralManagerDelegate
delegate handler rather than looking at it right after the initialization call. You will implement
- (void) centralManagerDidUpdateState: (CBCentralManager *) central;
There are some good examples that show this, such as Apple's heart rate monitor.