我希望您做得很好,遇到一个问题,当我搜索蓝牙设备时,我会获得一些带有名称的设备,但大多数设备不提供其名称,而那些设备在以下位置提供了名称Iphone的蓝牙,我尝试了一些解决方法
1-首先连接到设备,然后在委托中获得名称(peripheralDidUpdateName),在这种情况下,我得到了来自少数设备的响应,而其他设备则处于连接状态 2-我试图搜索一些延迟的设备,以便我可以找到名称,但仍然遇到相同的问题
extension LandingPage : CBCentralManagerDelegate , CBPeripheralManagerDelegate {
func centralManagerDidUpdateState(_ central: CBCentralManager) {
switch (central.state) {
case .poweredOff :
print("bluetooth is off ")
self.mainPeripheral.removeAll()
case .poweredOn :
print("bluetooth is on ")
manager?.scanForPeripherals(withServices: nil, options: nil)
}
}
return
实际结果:
<CBPeripheral: 0x282d090e0, identifier = D94CC0E6-0340-8406-4688-C38D593F3201, name = (null), state = disconnected>
<CBPeripheral: 0x282d0d040, identifier = 04F5A632-3FBE-47A6-C6A6-2DDF9975184C, name = (null), state = disconnected>
<CBPeripheral: 0x282d0d040, identifier = CE0FD194-7E7D-4004-C50B-049C2958F495, name = (null), state = disconnected>
<CBPeripheral: 0x282d0d040, identifier = E780781F-7D6B-8052-9743-ECFEB5C534C8, name = (null), state = disconnected>
预期:
<CBPeripheral: 0x282d0c0a0, identifier = 803732A6-31F9-A740-EC6A-8C9E3CDE8F71, name = Lefun, state = disconnected>
<CBPeripheral: 0x282d0d040, identifier = 6C19BC9F-1891-82DE-51D6-0C0E371F2E03, name = LH719, state = disconnected>