如何检索所有已连接的蓝牙设备

3

我正在尝试获取连接到iPhone的所有外围设备的列表。我已经连接了BOSE Soundlink,但它在我的应用中没有显示出来。我不知道UUID,所以将其传递为[],因为这应该可以获取所有设备吗?

func centralManagerDidUpdateState(_ central: CBCentralManager) {
    var message = ""

    switch central.state {
      case .poweredOn:
         message = "Bluetooth LE is turned on and ready for communication."

         // scan for ALL devices
        centralManager.scanForPeripherals(withServices: nil, options: nil)

         let connectedPeripherals = self.centralManager.retrieveConnectedPeripherals(withServices: []) 
        // WILL [] RETURN ALL CONNECTED PERIPHERALS?
        print("connectedPeripherals are \(connectedPeripherals)")
    }
}

1
这是真正的BLE,而不仅仅是经典蓝牙吗? - Larme
请不要在您的帖子中添加感谢,参见 https://meta.stackoverflow.com/questions/288160/no-thanks-damn-it - Vadim Kotov
不错的发现,Larme。Bose确实支持蓝牙经典模式。该死! - richc
@richc 你还记得你是怎么解决那个问题的吗? - Keselme
1个回答

3
如果您想获取所有连接的外围设备,我的建议是:将字符串180A作为参数添加到retrieveConnectedPeripherals中。所有蓝牙智能设备都实现了DEVICE INFORMATION(180A)服务(至少有这个)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接