【发布时间】: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 的回答我知道我可以做到,但是那个回答缺乏细节。现在我只是获取经典蓝牙设备的列表。
有人可以帮忙吗?
更新:
现在我找到了带有kIOBluetoothDeviceSearchClassic 和kIOBluetoothDeviceSearchLE 常量的.searchType 方法。在 viewDidLoad 我做了以下:
ioBlutoothmanager.searchType = IOBluetoothDeviceSearchLE.rawValue 但它仍然只能找到经典设备。
更新:
一直以来,它运行得如此正常,我没想到。它过滤了我不需要的所有设备,而且我没有 AirPods 来检查。
【问题讨论】:
标签: macos bluetooth core-bluetooth iobluetooth