Max*_*aev 7 macos bluetooth iobluetooth core-bluetooth
我有一个问题,通过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来检查.
好的,终于可以了。只需将searchType属性设置为IOBluetoothDeviceSearchLE.rawValue,即可从搜索中排除所有不必要的设备-正是我想要的。现在,我的搜索查询与默认的蓝牙浏览器完全相同。
ioBlutoothmanager.searchType = kIOBluetoothDeviceSearchLE.rawValue
也许有一天会有帮助
| 归档时间: | 
 | 
| 查看次数: | 485 次 | 
| 最近记录: |