此问题已在 Stack Overflow in 2013 上被问到, 但它需要更新。自 macOS 10.13 以来,macOS 的 Core Bluetooth 功能已更改,以使其更符合 iOS。
这个问题的答案是
CoreBluetooth is an iOS framework for Bluetooth LE communication. IOBluetooth is an OS X framework
这不再是真的了,Core Bluetooth 不是 独有的 iOS 框架,尽管 IOBluetooth 是 macOS 独有的
CoreBluetooth is for accessing Bluetooth Low Energy APIs. and IOBluetooth is for Bluetooth Classic Interface
这也不正确,因为 Core Bluetooth 并非专用于 BLE。
CoreBluetooth 文档指出:
Communicate with Bluetooth low energy and BR/EDR (“Classic”) Devices.
这看起来很简单; Core Bluetooth 用于蓝牙通信,包括 BLE 和 Classic。
IOBluetooth 文档指出:
Gain user-space access to Bluetooth devices.
但这并不是特别有启发性。
在 macOS 10.13+ 上的 CoreBluetooth 时代,IOBluetooth 与 macOS 上的 CoreBluetooth 的主要现代用例是什么?
最佳答案
CoreBluetooth 支持 BLE、GATT over BR/EDR 和 L2CAP。尽管它是摘要,但它不支持大多数经典配置文件。特别是,它仅支持 GATT over BR/EDR。它不支持其他协议(protocol)。 (根据我的经验,GATT over BR/EDR 非常罕见。我从未遇到过真正支持它的设备。)它不支持 SDP,不能用于发现大多数经典设备。
IOBluetooth 支持各种经典协议(protocol),包括 SDP、RFCOMM 和 L2CAP。它支持音频和 HCI 设备。据我所知,它并不直接支持 BLE;为此,它嵌入了 CoreBluetooth。 (我相信它可以对 BLE 进行一些非常低级别的发现,但这不是您想要使用的。)
我认为这在 10.13 中没有根本改变。最大的变化(我认为主要是为了支持 Catalyst)是 Core Bluetooth 在平台之间变得更加统一。我不认为这从根本上改变了框架的用途。
关于macos - Core Bluetooth 和 IOBluetooth 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68793810/