首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过IOBluetooth框架(macOS)获取BLE设备列表

如何通过IOBluetooth框架(macOS)获取BLE设备列表
EN

Stack Overflow用户
提问于 2018-06-08 17:13:54
回答 1查看 1.1K关注 0票数 7

我在通过IOBluetooth框架列出所有设备时遇到了问题。有什么方法不仅可以获得经典的,而且还可以获得BLE设备?

我的代码是

代码语言:javascript
复制
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方法,它包含kIOBluetoothDeviceSearchClassickIOBluetoothDeviceSearchLE常量。在viewDidLoad中,我做了以下工作:

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

UPD:

一直以来,它的工作是如此正常,我没想到。它过滤了我不需要的所有设备,我也没有AirPods来检查它。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-11 13:53:34

好的,它终于起作用了。只需将searchType属性设置为IOBluetoothDeviceSearchLE.rawValue,它就会将所有不必要的设备排除在搜索之外--这正是我所要寻找的。现在,我的搜索查询与默认的蓝牙资源管理器完全一样。

代码语言:javascript
复制
ioBlutoothmanager.searchType = kIOBluetoothDeviceSearchLE.rawValue

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

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50765541

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档