跳转到正文

@capgo/capacitor-bluetooth-low-energy

功能完备的 BLE 插件,支持扫描、连接、读取、写入蓝牙设备并接收通知

功能完备的 BLE 插件,支持扫描、连接、读取、写入蓝牙设备并接收通知

从 initialize() 以及下方列出的其他核心方法。

平台支持备注
iOS是原生
Android是原生
Web 端否使用 Capacitor.getPlatform() 做保护
  • initialize - 初始化 BLE 插件。必须在调用其他任何方法之前执行。
  • shimWebBluetooth - 在以下环境安装 Capacitor Web Bluetooth shim navigator.bluetooth。在 Capacitor 原生应用中使用 Web Bluetooth API 之前,请手动调用此方法。
  • isAvailable - 检查设备上是否支持蓝牙。
  • isEnabled - 检查设备上的蓝牙是否已开启。
方法描述
initialize初始化 BLE 插件。必须在调用任何其他方法之前调用。
shimWebBluetooth在 Capacitor 上安装 Web Bluetooth shim navigator.bluetooth。在 Capacitor 原生应用中使用 Web Bluetooth API 之前,请手动调用此方法。
isAvailable检查设备上的蓝牙是否可用。
isEnabled检查设备蓝牙是否已开启。
isLocationEnabled检查是否已启用定位服务(仅限 Android)。
openAppSettings打开应用设置页面。
openBluetoothSettings打开蓝牙设置页面(仅限 Android)。
openLocationSettings打开位置设置页面(仅限 Android)。
checkPermissions检查当前权限状态。
requestPermissions请求蓝牙权限。
startScan开始扫描 BLE 设备。
stopScan停止扫描 BLE 设备。
connect连接到 BLE 设备。
disconnect断开与 BLE 设备的连接。
createBond与 BLE 设备建立绑定(仅限 Android)。
isBonded检查设备是否已绑定(仅限 Android)。
discoverServices发现已连接设备上的服务。
getServices获取设备已发现的服务。
getConnectedDevices获取已连接设备列表。
readCharacteristic读取特征值。
writeCharacteristic向特征值写入数据。
startCharacteristicNotifications开启特征值通知。
stopCharacteristicNotifications停止某个特征的通知。
readDescriptor读取描述符的值。
writeDescriptor向描述符写入一个值。
readRssi读取已连接设备的 RSSI(信号强度)。
requestMtu请求更改 MTU 大小(仅限 Android)。
requestConnectionPriority请求连接优先级(仅限 Android)。
startAdvertising作为外围设备(BLE 服务器)开始广播。
stopAdvertising停止广播。
startForegroundService启动前台服务以在后台维持 BLE 连接(仅限 Android)。
stopForegroundService停止前台服务(仅限 Android)。
getPluginVersion获取原生 Capacitor 插件版本。
addListener添加设备扫描事件监听器。
addListener添加设备连接事件监听器。
addListener添加设备断开连接事件监听器。
addListener添加特征值变更事件监听器。
removeAllListeners移除该插件的所有监听器。

此参考文档同步自 src/definitions.ts 中的 capacitor-bluetooth-low-energy.

继续了解 @capgo/capacitor-bluetooth-low-energy

标题为“继续了解 @capgo/capacitor-bluetooth-low-energy”的章节

如果你正在使用 @capgo/capacitor-bluetooth-low-energy 要规划迁移和企业运营,请将其与 使用 @capgo/capacitor-bluetooth-low-energy 在“使用 @capgo/capacitor-bluetooth-low-energy”中的原生功能 Capgo 企业版 用于 Capgo Enterprise 中的产品工作流, Ionic Enterprise 插件替代方案 用于 Ionic Enterprise 插件替代方案的产品工作流, Capgo 替代方案 适用于 Capgo Alternatives 的产品工作流,以及 Capgo 咨询 适用于 Capgo Consulting 的产品工作流。