Lompat ke konten utama
Kembali ke plugin
@capgo/capacitor-Bluetooth Low Energy
Tutorial
oleh github.com/Cap-go

Bluetooth Low Energy

Plugin BLE yang lengkap untuk melakukan pemindaian, menghubungkan, membaca, menulis, dan menerima pemberitahuan dari perangkat Bluetooth

Petunjuk

Tutorial tentang Bluetooth Low Energy

Menggunakan @capgo/capacitor-bluetooth-low-energy

Capacitor Plugin Bluetooth Low Energy untuk komunikasi BLE.

Instal

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

Apa yang Dibuka oleh Plugin Ini

  • initialize - Inisialisasi plugin BLE. Harus dipanggil sebelum metode lainnya.
  • shimWebBluetooth - Pasang shim Web Bluetooth Capacitor pada navigator.bluetooth. Panggil secara manual sebelum menggunakan Web Bluetooth API dari aplikasi native Capacitor.
  • isAvailable - Periksa apakah Bluetooth tersedia pada perangkat.
  • isEnabled - Periksa apakah Bluetooth diaktifkan pada perangkat.

Contoh Penggunaan

initialize

Inisialisasi plugin BLE. Harus dipanggil sebelum metode lainnya.

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

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

shimWebBluetooth

Pasang shim Web Bluetooth Capacitor di navigator.bluetoothPanggil secara manual sebelum menggunakan Web Bluetooth API dari aplikasi native Capacitor.

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

BluetoothLowEnergy.shimWebBluetooth();

isAvailable

Periksa apakah Bluetooth tersedia pada perangkat.

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

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

isEnabled

Periksa apakah Bluetooth diaktifkan pada perangkat.

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

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

Referensi Lengkap