【问题标题】:How to get a list of BLE devices through IOBluetooth framework (macOS)如何通过 IOBluetooth 框架(macOS)获取 BLE 设备列表
【发布时间】:2018-11-18 19:17:47
【问题描述】:

我在通过IOBluetooth 框架列出所有设备时遇到问题。有没有办法不仅可以获得经典设备,还可以获得 BLE 设备?

我的代码是

let ioBluetoothManager = IOBluetoothDeviceInquiry(delegate: self)
var ioDevices = [IOBluetoothDevice]()
...
ioBluetoothManager?.start()
...

func deviceInquiryStarted(_ sender: IOBluetoothDeviceInquiry!) {
    print("started")
}
///
//IOBluetoothDeviceInquiryDelegate
///

func deviceInquiryDeviceFound(_ sender: IOBluetoothDeviceInquiry!, device: IOBluetoothDevice!) {
    print("found device")
    ioDevices.append(device)
    scrubber.reloadData()
    tableView.reloadData()
}

func deviceInquiryComplete(_ sender: IOBluetoothDeviceInquiry!, error: IOReturn, aborted: Bool) {
    print("completed")
}

我知道我可以使用 CoreBluetooth 做到这一点,但我还需要过滤设备以匹配特定条件。

来自this 的回答我知道我可以做到,但是那个回答缺乏细节。现在我只是获取经典蓝牙设备的列表。

有人可以帮忙吗?

更新:

现在我找到了带有kIOBluetoothDeviceSearchClassickIOBluetoothDeviceSearchLE 常量的.searchType 方法。在 viewDidLoad 我做了以下:

ioBlutoothmanager.searchType = IOBluetoothDeviceSearchLE.rawValue 但它仍然只能找到经典设备。

更新:

一直以来,它运行得如此正常,我没想到。它过滤了我不需要的所有设备,而且我没有 AirPods 来检查。

【问题讨论】:

    标签: macos bluetooth core-bluetooth iobluetooth


    【解决方案1】:

    好的,所以它终于开始工作了。只需将 searchType 属性设置为 IOBluetoothDeviceSearchLE.rawValue,它就会从搜索中排除所有不必要的设备——这正是我想要的。现在我的搜索查询与默认的蓝牙资源管理器完全一样。

    ioBlutoothmanager.searchType = kIOBluetoothDeviceSearchLE.rawValue
    

    也许有一天它会对某人有所帮助

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-24
    • 1970-01-01
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    • 2016-05-31
    相关资源
    最近更新 更多