指南
蓝牙低功耗的教程
使用@capgo/capacitor-bluetooth-low-energy
Capacitor蓝牙低功耗插件,用于BLE通信
安装
bun add @capgo/capacitor-bluetooth-low-energy
bunx cap sync
此插件暴露的内容
initialize- 初始化 BLE 插件。必须在调用任何其他方法之前。shimWebBluetooth- 安装 Capacitor Web Bluetooth shim。navigator.bluetooth在 Capacitor 本机应用程序中使用 Web Bluetooth API 之前,手动调用此方法。isAvailable- 检查设备上是否可用蓝牙。isEnabled- 检查设备蓝牙是否已启用。
示例使用
initialize
初始化 BLE 插件。必须在调用任何其他方法之前。
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.initialize({ mode: 'central' });
shimWebBluetooth
安装 Capacitor Web Bluetooth shim。 navigator.bluetooth在 Capacitor 本机应用程序中使用 Web Bluetooth API 之前,手动调用此方法。
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
BluetoothLowEnergy.shimWebBluetooth();
isAvailable
检查设备上是否可用蓝牙。
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { available } = await BluetoothLowEnergy.isAvailable();
isEnabled
检查设备上的蓝牙是否已启用.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { enabled } = await BluetoothLowEnergy.isEnabled();
全参考
- GitHub. https://github.com/Cap-go/capacitor-bluetooth-low-energy/
- 文档:/docs/plugins/bluetooth-low-energy/
继续使用@capgo/capacitor-bluetooth-low-energy
如果您正在使用 使用@capgo/capacitor-bluetooth-low-energy 来规划原生插件工作,连接它与 @capgo/capacitor-bluetooth-low-energy 以获取@capgo/capacitor-bluetooth-low-energy中的实现细节 Getting Started 为 Getting Started 中的实现细节, Capgo 插件目录 为 Capgo 插件目录中的产品工作流程, Capacitor 由 Capgo 提供的插件 为 Capacitor 由 Capgo 提供的插件中的实现细节,和 添加或更新插件 为添加或更新插件中的实现细节。