在CBCentralManager委托方法didDiscoverPeripheral:从来没有调用
我在主队列中的viewdidload
初始化CBCenteralManager
。 第一次更新状态方法被调用,开始扫描蓝牙设备,但didDiscoverPeripheral:
委托方法永远不会被调用。
代码是:
- (void)viewDidLoad { [super viewDidLoad]; self.CM = [[CBCentralManager alloc]initWithDelegate:self queue:nil]; } -(void)centralManagerDidUpdateState:(CBCentralManager *)central{ if (central.state == CBCentralManagerStatePoweredOn) { [self.CM scanForPeripheralsWithServices:nil options:nil]; } } - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral(CBPeripheral*)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI { } -(void)centralManager:(CBCentralManager *)central didRetrievePeripherals:(NSArray *)peripherals{ } -(void)centralManager:(CBCentralManager *)central didRetrieveConnectedPeripherals:(NSArray *)peripherals{ } -(void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{ } -(void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{ } -(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral{ }