Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 具有特定标识符的核心蓝牙扫描外设_Swift_Core Bluetooth_Identifier_Peripherals - Fatal编程技术网

Swift 具有特定标识符的核心蓝牙扫描外设

Swift 具有特定标识符的核心蓝牙扫描外设,swift,core-bluetooth,identifier,peripherals,Swift,Core Bluetooth,Identifier,Peripherals,我目前正在使用CoreBluetooth扫描我以前用特定标识符连接过的外设,然后只连接到外设。我知道我可以通过扫描带有服务的外设来实现这一点,然后与标识符进行比较(如果条件满足),然后按照下面的代码连接到外设 func discoverDevices(){ centralManager.scanForPeripheralsWithServices([CBUUID(string: "1234")], options: nil) } func centralManager(central:

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

有没有其他合适的方法直接扫描特定的外设?谢谢

据我所知,核心蓝牙不允许您直接扫描特定外设

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

您只需扫描一次,并在发现后保留对
CBPeripheral
对象的引用。然后,您可以稍后使用
连接外围设备:选项: