我有蓝牙助听器。它们具有不同的设备名称和相同的服务UUID。
我想我的应用可以同时连接它们。我该怎么办?
我的代码只能连接一个外围设备。
我的代码:
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
print("Find device: \(String(describing: peripheral.name))")
guard peripheral.name != nil else {
return
}
guard peripheral.name?.range(of: "HD100-5201000") != nil else {
return
}
guard peripheral.name?.range(of: "HD100-5200526") != nil else {
return
}
central.stopScan()
if peripheral.name?.range(of: "HD100-5201000") != nil {
connectPeripheral = peripheral
connectPeripheral.delegate = self
centralManager.connect(connectPeripheral, options: nil)
}
if peripheral.name?.range(of: "HD100-5200526") != nil {
connectPeripheral = peripheral
connectPeripheral.delegate = self
centralManager.connect(connectPeripheral, options: nil)
}
}
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
charDictionary = [:]
peripheral.discoverServices(nil)
}