问题陈述:如果我有多个 BLE,我将它们一一连接。但是现在当超过 1 个 BLE 同时超出范围时,我无法检测到核心蓝牙框架中央管理器中的状态。
解释 -
1)如果我有一个BLE并且我连接到那个BLE,当那个BLE超出范围时,它会调用- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
外围设备的方法。
2) 在- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
方法中- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
,只要 BLE 再次进入该范围,我就要求将其连接起来。
3) 这种行为适用于单个 BLE 一次超出范围的情况。并在进入范围内时再次连接。
4) 但当多个 BLE 同时超出范围时,上述行为效果不佳。
这是我的- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
代码
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
[self.btMainDashboardViewController.tagsTableView reloadData];
for (CBPeripheral *peripheral in self.btMainDashboardViewController.app.addedTagsArray) {
if (peripheral.state == CBPeripheralStateDisconnected) {
// if tag is not released go for autoconnection
[self.centralManager connectPeripheral:peripheral options:nil];
}
}
}
提前致谢。