[英]iOS Bluetooth: central- peripheral got connected before accepting pairing request
[英]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.