【问题标题】:CoreBluetooth scan peripheral with specific identifier具有特定标识符的 CoreBluetooth 扫描外围设备
【发布时间】:2016-05-06 19:07:17
【问题描述】:

我目前正在使用 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)
    }
}

有没有其他适当的方法可以直接扫描特定的外围设备?谢谢

【问题讨论】:

标签: swift core-bluetooth identifier peripherals


【解决方案1】:

据我所知,CoreBluetooth 不允许您直接扫描特定外围设备。

但是,您可以通过调用retrievePeripheralsWithIdentifiers: 来检查它是否已经是系统的已知外围设备。

您只需要扫描一次并在发现CBPeripheral 对象后保留它的引用。然后您可以稍后使用connectPeripheral:options: 请求连接到它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-04
    • 1970-01-01
    • 2015-03-13
    相关资源
    最近更新 更多