Aller directement au contenu principal
Retour aux plugins
@capgo/capacitor-Bluetooth faible énergie
Tutoriel
par github.com/Cap-go

Bluetooth faible énergie

Plugin BLE complet pour la recherche, la connexion, la lecture, l'écriture et la réception de notifications de dispositifs Bluetooth

Guide

Tutoriel sur Bluetooth Low Energy

Utilisation de @capgo/capacitor-bluetooth-low-energy

Capacitor Bluetooth Low Energy Plugin pour la communication BLE.

Installer

bun add @capgo/capacitor-bluetooth-low-energy
bunx cap sync

Ce que ce Plugin Expose

  • initialize - Initialiser le plugin BLE. Doit être appelé avant toute autre méthode.
  • shimWebBluetooth - Installer le shim Web Bluetooth de Capacitor sur navigator.bluetooth. Appeler cela manuellement avant d'utiliser le Web Bluetooth API à partir d'une application native Capacitor.
  • isAvailable - Vérifiez si le Bluetooth est disponible sur le dispositif.
  • isEnabled - Vérifiez si le Bluetooth est activé sur le dispositif.

Exemple d'utilisation

initialize

Initialisez le plugin BLE. Doit être appelé avant toute autre méthode.

import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';

await BluetoothLowEnergy.initialize({ mode: 'central' });

shimWebBluetooth

Installez le shim Web Bluetooth Capacitor sur navigator.bluetoothAppellez cela manuellement avant d'utiliser le Web Bluetooth API à partir d'une application native Capacitor.

import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';

BluetoothLowEnergy.shimWebBluetooth();

isAvailable

Vérifiez si le Bluetooth est disponible sur le dispositif.

import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';

const { available } = await BluetoothLowEnergy.isAvailable();

isEnabled

Vérifiez si le Bluetooth est activé sur le dispositif.

import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';

const { enabled } = await BluetoothLowEnergy.isEnabled();

Référence complète