使用@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在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_KEEP_0__/__CAPGO_KEEP_1__-bluetooth-low-energy 使用@capgo/capacitor-bluetooth-low-energy 为了计划原生插件的工作,连接它与 @capgo/capacitor-低功耗蓝牙 对于@capgo/capacitor-低功耗蓝牙的实现细节, 开始使用 对于开始使用的实现细节, Capgo 插件目录 对于Capgo 插件目录中的产品工作流程, Capacitor 由Capgo提供的插件 对于Capacitor 由Capgo提供的插件的实现细节,以及 添加或更新插件 对于添加或更新插件的实现细节。