使用@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蓝牙模拟器。 navigator.bluetooth在Capacitor原生应用中使用Web蓝牙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-低功耗蓝牙 中 在 @capgo/capacitor-低功耗蓝牙 中的实现细节 开始使用 在开始使用中实现细节 Capgo 插件目录 在 Capgo 插件目录 中的产品工作流程 Capacitor 由 Capgo 提供的插件 在 Capacitor 由 Capgo 提供的插件 中的实现细节 添加或更新插件 在添加或更新插件 中的实现细节