使用@capgo/capacitor-bluetooth-low-energy
Capacitor蓝牙低功耗插件用于BLE通信
安装
bun add @capgo/capacitor-bluetooth-low-energy
bunx cap sync
此插件暴露的内容
initialize- 初始化BLE插件。必须在调用任何其他方法之前调用。shimWebBluetooth- 安装Capacitor Web Bluetooth shim onnavigator.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.手动调用此方法之前使用Web蓝牙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
如果您正在使用 使用@capgo/capacitor-bluetooth-low-energy 为native插件工作做好规划,连接它 @capgo/capacitor蓝牙低功耗 关于@capgo/capacitor蓝牙低功耗的实现细节 开始 关于开始的实现细节 Capgo插件目录 关于Capgo插件目录中的产品工作流程 Capacitor由Capgo的插件 关于Capacitor由Capgo的插件的实现细节 添加或更新插件 关于添加或更新插件的实现细节