[英]Connect to multiple BLE devices simultaneously iOS
我正在嘗試掃描附近所有可用的BLE設備,並與每個設備建立連接,這樣我就可以繼續獲取RSSI值。
這是我的代碼:
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral
advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
NSLog(@"Received peripheral : \n%@", peripheral);
myPeripheral=peripheral;
NSLog(@"RSSI value:%@",RSSI);
[myCentralManager connectPeripheral:peripheral options:nil];
peripheral.delegate=self;
}
-(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral{
//NSLog(@"Peripheral Connected");
NSLog(@"%@ connected",peripheral.identifier);
}
誰能指導我如何建立與多個外圍設備的連接? 謝謝
這是您可以執行的操作:
步驟1:停止掃描。 這有助於加快連接速度。
[self.centralManager stopScan];
步驟2:掃描外圍設備。
[self.centralManager scanForPeripheralsWithServices:nil options:nil];
步驟3:將所有發現的外圍設備保存在下面的委托回調方法中。
centralManager:didDiscoverPeripheral:advertisementData:RSSI:
步驟2.1:之所以稱為2.1,是因為connectPeripheral:options:
在步驟2之后立即執行。使用GCD,在延遲2-5秒(用戶dispatch_after
)后調度線程,並在保存的Per上循環並調用connectPeripheral:options:
方法以連接到他們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.