我在通过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中做到这一点,但我也需要过滤设备以符合特定的标准。
从这的答案,我知道我可以做到,但这个答案缺乏细节。现在,我只是得到了一份经典蓝牙设备的清单。
有人能帮忙吗?
UPD:
现在我找到了.searchType方法,它包含kIOBluetoothDeviceSearchClassic和kIOBluetoothDeviceSearchLE常量。在viewDidLoad中,我做了以下工作:
ioBlutoothmanager.searchType = IOBluetoothDeviceSearchLE.rawValue,但它仍然只找到经典的设备。
UPD:
一直以来,它的工作是如此正常,我没想到。它过滤了我不需要的所有设备,我也没有AirPods来检查它。
发布于 2018-06-11 13:53:34
好的,它终于起作用了。只需将searchType属性设置为IOBluetoothDeviceSearchLE.rawValue,它就会将所有不必要的设备排除在搜索之外--这正是我所要寻找的。现在,我的搜索查询与默认的蓝牙资源管理器完全一样。
ioBlutoothmanager.searchType = kIOBluetoothDeviceSearchLE.rawValue也许总有一天它会对某人有所帮助
https://stackoverflow.com/questions/50765541
复制相似问题