使用 @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. 在使用 Web Bluetooth API 的 Capacitor 本机应用之前,手动调用此方法。isAvailable- 检查设备上的蓝牙是否可用。isEnabled- 检查设备上的蓝牙是否已启用。
示例用途
initialize
初始化 BLE 插件。必须在调用任何其他方法之前调用。
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.initialize({ mode: 'central' });
shimWebBluetooth
在 Capacitor 上安装 Web Bluetooth shim navigator.bluetooth。手动调用此方法之前使用 Web Bluetooth API 从 Capacitor 原生应用。
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
If you are using 使用 @capgo/capacitor-bluetooth-low-energy 为了规划原生插件的工作,连接它与 @capgo/capacitor-bluetooth-low-energy 查看 @capgo/capacitor-bluetooth-low-energy 的实现细节 开始 查看 Getting Started 的实现细节 Capgo 插件目录 了解 Capgo 插件目录中的产品工作流程 Capacitor 由 Capgo 提供的插件 了解 Capacitor 由 Capgo 提供的插件的实现细节 添加或更新插件 为添加或更新插件的实现细节。