Zum Hauptinhalt springen
Zurück zu plugins
@capgo/capacitor-bluetooth-low-energy
Tutorial
von github.com/Cap-go

Bluetooth Low Energy

Vollwertiger BLE-Plugin für das Scannen, Verbinden, Lesen, Schreiben und Empfangen von Benachrichtigungen von Bluetooth-Geräten

Richtlinie

Tutorial zum Bluetooth Low Energy

Mit @capgo/capacitor-bluetooth-low-energy

Capacitor Bluetooth Low Energy Plugin für BLE-Kommunikation.

Installieren

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

Was diese Plugin-Exposé enthält

  • initialize - Initialisieren Sie das BLE-Plugin. Muss vor der Verwendung jeder anderen Methode aufgerufen werden.
  • shimWebBluetooth - Installieren Sie den Capacitor Web Bluetooth Shim auf navigator.bluetooth. Ruf diese Methode manuell vor der Verwendung des Web Bluetooth API aus einer Capacitor native App auf.
  • isAvailable - Überprüfen Sie, ob Bluetooth auf dem Gerät verfügbar ist.
  • isEnabled - Überprüfen Sie, ob Bluetooth auf dem Gerät aktiviert ist.

Beispielanwendung

initialize

Initialisieren Sie das BLE-Plugin. Muss vor der Verwendung jeder anderen Methode aufgerufen werden.

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

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

shimWebBluetooth

Installieren Sie das Capacitor Web Bluetooth Shim auf navigator.bluetoothRufen Sie diese Funktion manuell auf, bevor Sie das Web Bluetooth API aus einer Capacitor nativen App verwenden.

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

BluetoothLowEnergy.shimWebBluetooth();

isAvailable

Überprüfen Sie, ob Bluetooth auf dem Gerät verfügbar ist.

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

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

isEnabled

Überprüfen Sie, ob Bluetooth auf dem Gerät aktiviert ist.

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

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

Vollständige Referenz