What causes CBCentralManagerStateUnknown in iOS?

后端 未结 6 2745
灰色年华
灰色年华 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:55

    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.

提交回复
热议问题