What causes CBCentralManagerStateUnknown in iOS?

后端 未结 6 2747
灰色年华
灰色年华 2021-02-20 06:15

Why do I get CBCentralManagerStateUnknown on an iPad 2 when using this simple code?

- (BOOL)viewDidLoad {

    bluetoothManager = [[CBCentralManager         


        
6条回答
  •  无人共我
    2021-02-20 06:51

    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.

提交回复
热议问题