简体   繁体   English

扫描时如何获取断开的BLE列表?

[英]How to get list of disconnected BLE while scanning?

Please check following code: 请检查以下代码:

NSDictionary *scanOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
[centralManager scanForPeripheralsWithServices:nil options:scanOptions];

I'm able to scan all the BLEs and connect successfully. 我能够扫描所有BLE并成功连接。 I have a button in my app to scan again for BLEs. 我的应用程序中有一个按钮,可以再次扫描BLE。 When I try to scan again using above code, it scans all the BLEs and disconnect all the BLEs which are already connected. 当我尝试使用上述代码再次扫描时,它将扫描所有BLE并断开所有已连接的BLE。

So is there any way to scan only for those Peripherals which are not connected. 因此,有什么方法可以只扫描那些未连接的外围设备。

Thanks in advance! 提前致谢!

NO,there isn't a way to scan only for the connected Peripherals. 否,没有一种方法只能扫描连接的外围设备。

As - scanForPeripheralsWithServices:options: method is the only way to scan for Peripherals,You can scan only for the Peripherals with special services by specify the services parameter. - scanForPeripheralsWithServices:options:方法是扫描外围设备的唯一方法,您可以通过指定services参数仅扫描具有特殊服务的外围设备。 Or you can specify CBCentralManagerScanOptionAllowDuplicatesKey and CBCentralManagerScanOptionSolicitedServiceUUIDsKey in options parameter,both have nothing to do with connect state. 或者,您可以在options参数中指定CBCentralManagerScanOptionAllowDuplicatesKeyCBCentralManagerScanOptionSolicitedServiceUUIDsKey ,两者都与连接状态无关。

But you can discover all peripherals and pick out the disconnected peripherals by check the peripheral's state in callback: - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *,id> *)advertisementData RSSI:(NSNumber *)RSSI 但是您可以发现所有外围设备,并通过在回调中检查外围设备的state来找出断开连接的外围设备- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *,id> *)advertisementData RSSI:(NSNumber *)RSSI

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM