簡體   English   中英

具有特定標識符的CoreBluetooth掃描外圍設備

[英]CoreBluetooth scan peripheral with specific identifier

我目前正在使用CoreBluetooth掃描我之前使用特定標識符連接的外圍設備,然后僅連接到外圍設備。 我知道我可以通過掃描帶有服務的外圍設備來做到這一點,然后如果條件滿足則與標識符進行比較,然后按以下代碼連接到外圍設備

func discoverDevices(){
    centralManager.scanForPeripheralsWithServices([CBUUID(string: "1234")], options: nil)
}
func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) {
    if peripheral.identifier == NSUUID(UUIDString: "AD4612DG87-7512-683D-79RT-234DFG987RUI{
    self.centralManager.connectPeripheral(peripheral, options: nil)
    }
}

還有其他適當的方法可以直接掃描特定的外圍設備嗎? 謝謝

據我所知,CoreBluetooth不允許您直接掃描特定的外圍設備。

但是,您可以通過調用retrievePeripheralsWithIdentifiers:來檢查它是否是系統的已知外圍設備。

您只需要掃描一次,並在發現它之后保留對CBPeripheral對象的引用。 然后,您可以稍后使用connectPeripheral:options:請求與其建立連接connectPeripheral:options:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM