Bluetooth 是一个 Swift 软件包,包含多个库,支持蓝牙 SIG 规范和协议,包括 GAP、GATT、HCI、L2CAP、Classic (BR/EDR) 和低功耗 (Low Energy) 支持。
import Bluetooth
let uuid128bit = BluetoothUUID(rawValue: "60F14FE2-F972-11E5-B84F-23E070D5A8C7")
let uuid16bit = BluetoothUUID(rawValue: "FEA9")
let address = BluetoothAddress(rawValue: "00:1A:7D:DA:71:13")
Bluetooth 可以作为 Swift Package Manager 软件包使用。 要使用它,请在您的 Package.swift
中添加以下依赖项
.package(url: "https://github.com/PureSwift/Bluetooth.git", branch: "master"),
并将 Bluetooth
添加到您的目标依赖项中。 然后您可以 import Bluetooth
来访问蓝牙功能。
对不同操作系统和平台的支持分布在一套 Swift 软件包中,这些软件包都依赖于此软件包作为基础。 它目前支持 WebAssembly (Chrome, Edge)、Android、嵌入式 Swift、桌面 Linux (Debian, Fedora, Arch)、Buildroot 和 Yocto Linux。
平台 | 角色 | 后端 | 库 |
---|---|---|---|
macOS, iOS, watchOS, tvOS, visionOS | 中央, 外围 | CoreBluetooth | DarwinGATT |
Linux | 中央, 外围 | BlueZ | BluetoothLinux, GATT |
Android | 中央 | Java 本地接口 (Java Native Interface) | AndroidBluetooth |
WebAssembly | 中央 | Bluetooth Web API | BluetoothWeb |
Pi Pico W | 外围 | BlueKitchen BTStack | BTStack |
ESP32 | 外围 | Apache NimBLE | NimBLE |
nRF52840 | 外围 | Zephyr SDK | Zephyr |
Bluetooth 在 MIT 许可证下发布。 有关详细信息,请参阅 LICENSE。