LoginSignup
5
1

More than 3 years have passed since last update.

BleManager option

Last updated at Posted at 2020-02-13

BleManageroption

BleManager

スキャンoptionでconnect成功率、速度向上できます

Android

まずAndroidじゃ!

  • scanningOptions - JSON - [Android only] after Android 5.0, user can control specific ble scan behaviors:

    • numberOfMatches - Number - corresponding to setNumOfMatches
    • matchMode - Number - corresponding to setMatchMode
    • scanMode - Number - corresponding to setScanMode
    • reportDelay - Number - corresponding to setReportDelay // 現在サポートされていない模様
  • scanningOptions - JSON - [Androidのみ] Android 5.0以降、ユーザーは特定のbleスキャン動作を制御できます。

    • numberOfMatches - Number - Bluetooth LEスキャンフィルターのハードウェア一致の一致数を設定する
    • matchMode - Number - Bluetooth LEスキャンフィルターの一致モードをハードウェア一致に設定する
    • scanMode - Number - Bluetooth LEスキャンのスキャンモードを設定します。

    詳細

  • numberOfMatches

    • MATCH_NUM_MAX_ADVERTISEMENT

    • hwのリソースの現在の機能と可用性に依存します。

    • 定数値:3(0x00000003)

    • MATCH_NUM_FEW_ADVERTISEMENT

    • フィルターごとにいくつかの広告に一致します。hwのリソースの現在の機能と可用性に依存します

    • 定数値:2(0x00000002)

    • MATCH_NUM_ONE_ADVERTISEMENT

    • フィルターごとに1つの広告に一致

    • 定数値:1(0x00000001)

  • setMatchMode

    • MATCH_MODE_AGGRESSIVE

    • アグレッシブモードでは、信号強度が弱く、期間中に目撃/一致の数が少ない場合でも、hwは一致をより早く決定します。

    • 定数値:1(0x00000001)

    • MATCH_MODE_STICKY

    • スティッキーモードの場合、hwでレポートする前に、信号強度と目撃のより高いしきい値が必要です。

    • 定数値:2(0x00000002)

    • scanMode

      • SCAN_MODE_LOW_POWER

      • 低電力モードでBluetooth LEスキャンを実行します。これは最小の電力を消費するため、デフォルトのスキャンモードです。このモードは、スキャンアプリケーションがフォアグラウンドにない場合に適用されます。

      • 定数値:0(0x00000000)

      • SCAN_MODE_BALANCED

      • バランス電源モードでBluetooth LEスキャンを実行します。スキャン結果は、スキャン頻度と消費電力のバランスが取れたレートで返されます。

      • 定数値:1(0x00000001)

      • SCAN_MODE_LOW_LATENCY

      • 最高のデューティサイクルを使用してスキャンします。アプリケーションがフォアグラウンドで実行されている場合にのみ、このモードを使用することをお勧めします。

      • 定数値:2(0x00000002)

      • SCAN_MODE_OPPORTUNISTIC

      • 特別なBluetooth LEスキャンモード。このスキャンモードを使用するアプリケーションは、BLEスキャンを開始せずに他のスキャン結果を受動的にリッスンします。

      • 定数値:-1(0xffffffff)

iOS

まず参考記事

For example, when your app is relaunched by system, you can retrieve all the restoration identifiers for the central manager objects the system was preserving for your app, like this:
After you have the list of restoration identifiers, simply loop through it and reinstantiate the appropriate central manager objects.

システムがアプリのために保存していた中央マネージャーオブジェクトのすべての復元識別子を取得できます。
復元識別子のリストを取得したら、単純にループして、適切な中央マネージャーオブジェクトを再インスタンス化します。

効果

前のスキャンでconnectしたBLEに対してスキャンすっ飛ばしてconnectするようになるので劇的に早くなる(3秒)
見つけられなければ通常スキャンに切り替わる

使い方

  • xcodebackgroud processing on
  • infoにrestoreIdentifierKey任意のキー追加
  • retrieveServicesooption指定すればokよ

例 

    if (!isAndroid) {
      BleManager.start({ showAlert: false, restoreIdentifierKey: 'bitkey', forceLegacy: true });
    }

気をつけないと行けないのがretrieveServicesooptionを指定してしまうとAndroidのスキャンが正常に動かないので
条件分岐などで避けてください!

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1