BabyBluetooth icon indicating copy to clipboard operation
BabyBluetooth copied to clipboard

为什么点击连接后,会一直连接其他设备,

Open tracyYBY opened this issue 7 years ago • 4 comments

baby.having(self.currPeripheral).connectToPeripherals().discoverServices().discoverCharacteristics().readValueForCharacteristic().discoverDescriptorsForCharacteristic().readValueForDescriptors().begin();

会调连接成功,但是也会一直连接其他设备,而且收不到didUpdateValueForCharacteristic 的回调

tracyYBY avatar Aug 03 '17 09:08 tracyYBY

我也是,其它的设备也都一块连上了,请问是怎么解决的

qiaovc avatar Oct 21 '17 06:10 qiaovc

[baby setFilterOnConnectToPeripherals:^BOOL(NSString *peripheralName, NSDictionary *advertisementData, NSNumber *RSSI) { return [weakSelf.curPeripheral.name isEqualToString:peripheralName]; }];

在过滤器中过滤就行了

1037390459 avatar Nov 08 '17 08:11 1037390459

@1037390459 不是说过滤掉就可以了,而是你已经指定连哪一个

baby.having(self.currPeripheral).

可结果却是连了所有设备,莫名其妙

SKbutton avatar Jan 16 '19 16:01 SKbutton

看源码判断 if (poweredOn) { self.CENTRAL_MANAGER_INIT_WAIT_TIMES = 0; //扫描后连接 if (self.babyCentralManager->needScanForPeripherals) { //开始扫描peripherals [self.babyCentralManager scanPeripherals]; } //直接连接 else { if (cachedPeripheral) { [self.babyCentralManager connectToPeripheral:cachedPeripheral]; } } return; } 因为调用了connectToPeripherals(),所以needScanForPeripherals为YES,那么就开始扫码所有了。

yinanwang1 avatar Jun 27 '19 08:06 yinanwang1