__CAPGO_KEEP_0__
@capgo/capacitor-bluetooth-low-energy デバイスAPI オープンソース

Bluetooth Low Energy Capacitor プラグイン

Bluetooth デバイスからスキャン、接続、読み取り、書き込み、通知を受信するためのフル機能のBLE プラグイン

インストール

bun add @capgo/capacitor-bluetooth-low-energy bunx cap sync
npm、pnpm、またはyarn
  • npm install @capgo/capacitor-bluetooth-low-energy
  • pnpm add @capgo/capacitor-bluetooth-low-energy
  • yarn add @capgo/capacitor-bluetooth-low-energy

ガイド

CapacitorでBluetooth Low Energyを使用する方法

@capgo/capacitor-bluetooth-low-energyを使用する方法

CapacitorのBluetooth Low EnergyプラグインはBLE通信に使用されます。

インストール

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

bunx cap sync プラグインのネイティブcodeをプロジェクトにコピーします。プラグインのアップグレード後は、再度実行してください。

インポート

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

APIの概要

メソッド 説明
initialize BLE プラグインを初期化します。どのメソッドよりも前に呼び出す必要があります。
shimWebBluetooth Capacitor Web Bluetooth シムをインストールします。 navigator.bluetoothWeb ブルートゥース API を使用する前に、Web ブルートゥース Capacitor を手動で呼び出してください。
isAvailable __CAPGO_KEEP_1__
isEnabled Bluetooth が利用可能かどうかを確認します。
isLocationEnabled Bluetooth が有効かどうかを確認します。
openAppSettings 位置情報サービスが有効かどうか (Android 限定) を確認します。
openBluetoothSettings アプリの設定画面を開きます。
openLocationSettings Android用の場所の設定ページを開きます。
checkPermissions 現在の許可状況を確認してください。
requestPermissions Bluetoothの許可を求めます。
startScan BLEデバイスのスキャンを開始します。
stopScan BLEデバイスのスキャンを停止します。
connect BLEデバイスに接続します。
disconnect BLEデバイスから切断します。
createBond Android用のBLEデバイスとバンドを形成します。
isBonded Android用のデバイスがバンドされているかどうかを確認します。
discoverServices 接続されたデバイスでサービスを検出します。
getServices デバイスの検出されたサービスを取得します。
getConnectedDevices 接続済みのデバイスの一覧を取得します。
readCharacteristic 特性値を読み取ります。
writeCharacteristic 特性に値を書き込みます。
startCharacteristicNotifications 特性の通知を開始します。
stopCharacteristicNotifications 特性の通知を停止します。
readDescriptor デスクリプター値を読み取ります。
writeDescriptor デスクリプターに値を書き込みます。
readRssi 接続されたデバイスのRSSI(信号強度)を読み取ります。
requestMtu MTUサイズ変更を要求(Androidのみ)。
requestConnectionPriority 接続優先度を要求(Androidのみ)。
startAdvertising BLEサーバーとしてアドバタイズを開始します。
stopAdvertising アドバタイズを停止します。
addGattService GATTサービスと特性をローカルGATTサーバーに追加します。パーサルモードでアドバタイズを開始する前に呼び出してください。
removeGattService Bluetooth Low Energyプラグイン
setGattCharacteristicValue Bluetooth Low Energyプラグイン
notifyGattCharacteristicChanged Bluetooth Low Energyプラグイン
startForegroundService Androidのみで、バックグラウンドでBLE接続を維持するために、前景サービスを開始します。
stopForegroundService Androidのみで、前景サービスを停止します。

例

initialize()

BLEプラグインを初期化します。どの他のメソッドよりも前に呼び出す必要があります。

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

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

shimWebBluetooth()

Web Bluetooth shimをCapacitorにインストールします。 navigator.bluetoothCapacitorネイティブアプリからWeb Bluetooth APIを使用する前に、手動で呼び出してください。

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

BluetoothLowEnergy.shimWebBluetooth();

isAvailable()

デバイス上のBluetoothが利用可能かどうかを確認します。

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

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

isEnabled()

デバイス上のBluetoothが有効かどうかを確認します。

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

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

isLocationEnabled()

Androidのみで、位置情報サービスが有効かどうかを確認します。

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

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

openAppSettings()

アプリの設定ページを開きます。

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

await BluetoothLowEnergy.openAppSettings();

上の表には、36の基本メソッドがリストされています。リスナーとバージョンヘルパー、各メソッドのフルコントラクトは、 GitHub リポジトリ.

イベントをリスンする

addListener ハンドルを返します。画面がアンマウントされたとき、または handle.remove() すべてのリスナーをクリアするときに呼びます。 BluetoothLowEnergy.removeAllListeners() フルリファレンス

ドキュメント

@capgo/capacitor-bluetooth-low-energyを継続して使用

Capacitor Bluetooth Low Energyを使用している場合 @capgo/capacitor-Bluetooth低消耗エネルギー Capacitor Bluetooth Low Energyを接続 @capgo/capacitor-bluetooth-low-energy @capgo/capacitor-Bluetooth低エネルギー Capacitor Bluetooth Low Energyの実装詳細については、Capacitor Bluetooth Low EnergyのGetting Startedを参照してください Capacitor プラグインディレクトリ Capgo プラグインディレクトリ for the product workflow in Capgo Plugin Directory, Capacitor Capgo プラグイン Capacitor Bluetooth Low Energy の実装詳細については、Capacitor プラグインによって Capgo によって。 Capacitor Bluetooth Low Energyの実装詳細についてはCapacitor Bluetooth Low EnergyのGetting Startedを参照してください Capacitor Bluetooth Low Energy プラグインの使用方法

FAQ

Bluetooth Low Energy プラグイン FAQ

Bluetooth Low Energy プラグインを Capacitor アプリにどのようにインストールするか?

「bun add @capgo/capacitor-bluetooth-low-energy」 (または「npm install @capgo/capacitor-bluetooth-low-energy」) を実行し、次に「bunx cap sync」を実行して iOS と Android のプロジェクトがネイティブ code を取得するようにします。次に、@capgo/capacitor-bluetooth-low-energy をアプリケーション code からインポートします。

React、Vue、Angular と @capgo/capacitor-bluetooth-low-energy がどのように動作するか?

はい。Bluetooth Low Energy は Capacitor パッケージなので、Ionic、React、Vue、Angular、Svelte、または単純な JavaScript などの Capacitor 内で実行される任意の Web フレームワークと互換性があります。

どの Capacitor バージョンが @capgo/capacitor-bluetooth-low-energy をサポートする?

Capgo plugins follow Capacitor's major version: use the plugin major version that matches your Capacitor major version (for example plugin v8 with Capacitor 8). The compatibility table in the GitHub README lists the maintained versions.

は @capgo/capacitor-bluetooth-low-energy が無料でオープンソースですか?

Yes. The source code is public on GitHub at https://github.com/Cap-go/capacitor-bluetooth-low-energy/ and the package is free to install from npm. Bug reports and pull requests are welcome.

Bluetooth Low Energy を使用する code を App Store のレビューなしで更新できますか?

プラグインをインストールまたはアップグレードするとネイティブ code が変更されるため、新しいストアビルドが必要になります。その後、JavaScript、HTML、CSS の変更がプラグインを呼び出すと Capgo のライブアップデートで即座に配信できます。

アプリ レビューの待たずに Bluetooth Low Energy の変更を実装

プラグインがストアにビルドされたら、Capgo ライブ アップデートは、ユーザーに JavaScript、HTML、CSS の変更を数分でプッシュします。

Capgo で始めましょう