繁体   English   中英

iOS Core蓝牙外围设备连接请求

[英]IOS Core bluetooth peripheral connection request

在研究corebluetooth框架时,如果两个BLE都可见,我便能够发现并与该设备连接。 现在我遇到一个问题,一旦发现外围设备由于某种原因而关闭,便能够发现该设备,现在我尝试使用

[centralManager connectPeripheral:activePeripheral options:nil];

这种方法,但是外围设备无法连接,因此我需要在连接是否可用之前进行检查。

谢谢

您有一种方法:

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI

如果您添加如下扫描选项:

NSDictionary * options = [NSDictionary dictionaryWithObjectsAndKeys:@YES, CBCentralManagerScanOptionAllowDuplicatesKey, nil];
[manager scanForPeripheralsWithServices:nil options:options];

然后将连续调用上述方法以更新外围设备的状态。 然后,您可以观察一段时间未调用该方法的外围设备,然后从列表中删除该外围设备

或者第二种选择是在连接外围设备之前再次扫描它。

暂无
暂无

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

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