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