メインコンテンツにジャンプ

Getting Started

ターミナルウィンドウ
bun add @capgo/capacitor-ibeacon
bunx cap sync
import { CapacitorIbeacon } from '@capgo/capacitor-ibeacon';

地域のビーコン監視を開始します。地域に入ったり出たりするときにイベントが発生します。

import { CapacitorIbeacon } from '@capgo/capacitor-ibeacon';
await CapacitorIbeacon.startMonitoringForRegion({
identifier: 'MyBeaconRegion',
uuid: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D'
});

地域のビーコン監視を停止します。

import { CapacitorIbeacon } from '@capgo/capacitor-ibeacon';
await CapacitorIbeacon.stopMonitoringForRegion({
identifier: 'MyBeaconRegion',
uuid: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D'
});

地域内のビーコンを検出し、距離の更新を提供します。

import { CapacitorIbeacon } from '@capgo/capacitor-ibeacon';
await CapacitorIbeacon.startRangingBeaconsInRegion({
identifier: 'MyBeaconRegion',
uuid: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D'
});

__CAPGO_KEEP_0__を範囲内に停止します。

import { CapacitorIbeacon } from '@capgo/capacitor-ibeacon';
await CapacitorIbeacon.stopRangingBeaconsInRegion({
identifier: 'MyBeaconRegion',
uuid: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D'
});

startAdvertising

__CAPGO_KEEP_2__

__CAPGO_KEEP_0__デバイスをiBeaconとしてアドバタイズする (iOSのみ)。

import { CapacitorIbeacon } from '@capgo/capacitor-ibeacon';
await CapacitorIbeacon.startAdvertising({
uuid: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D',
major: 1,
minor: 2,
identifier: 'MyBeacon'
});

stopAdvertising

__CAPGO_KEEP_3__

__CAPGO_KEEP_0__デバイスをiBeaconとしてアドバタイズを停止する (iOSのみ)。

import { CapacitorIbeacon } from '@capgo/capacitor-ibeacon';
await CapacitorIbeacon.stopAdvertising();

requestWhenInUseAuthorization

__CAPGO_KEEP_4__

__CAPGO_KEEP_1__をクリップボードにコピー

import { CapacitorIbeacon } from '@capgo/capacitor-ibeacon';
const { status } = await CapacitorIbeacon.requestWhenInUseAuthorization();
console.log('Authorization status:', status);

Request “Always” location authorization (required for background monitoring).

import { CapacitorIbeacon } from '@capgo/capacitor-ibeacon';
const { status } = await CapacitorIbeacon.requestAlwaysAuthorization();
console.log('Authorization status:', status);

getAuthorizationStatus

getAuthorizationStatus

現在の位置の許可状態を取得します。

import { CapacitorIbeacon } from '@capgo/capacitor-ibeacon';
const { status } = await CapacitorIbeacon.getAuthorizationStatus();
console.log('Current status:', status);

isBluetoothEnabled

isBluetoothEnabled

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

import { CapacitorIbeacon } from '@capgo/capacitor-ibeacon';
const { enabled } = await CapacitorIbeacon.isBluetoothEnabled();
if (!enabled) {
console.log('Please enable Bluetooth');
}

isRangingAvailable

isRangingAvailable

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

import { CapacitorIbeacon } from '@capgo/capacitor-ibeacon';
const { available } = await CapacitorIbeacon.isRangingAvailable();
if (available) {
console.log('Ranging is supported');
}

enableARMAFilter

enableARMAFilter

距離計算 (Android 限定) に対して ARMA フィルタを有効にする。

import { CapacitorIbeacon } from '@capgo/capacitor-ibeacon';
await CapacitorIbeacon.enableARMAFilter({
enabled: true
});

バックグラウンドビーコン スキャン モードを有効または無効にする (Android 限定)。 この機能は、信頼できるバックグラウンド ビーコン 検出のために、 foreground サービスを有効にする。 「常に」位置認可を要求した後、必ず呼び出してください。

import { CapacitorIbeacon } from '@capgo/capacitor-ibeacon';
// Enable background mode for beacon scanning
await CapacitorIbeacon.enableBackgroundMode({ enabled: true });
// Disable background mode
await CapacitorIbeacon.enableBackgroundMode({ enabled: false });

バックグラウンド スキャン期間を設定する (Android 限定)。 バックグラウンドでビーコンを検出する際に、デバイスがスキャンする頻度と時間を制御します。

import { CapacitorIbeacon } from '@capgo/capacitor-ibeacon';
// Set background scan to 10 seconds every 30 seconds
await CapacitorIbeacon.setBackgroundScanPeriod({
scanPeriod: 10000, // 10 seconds of scanning
betweenScanPeriod: 30000 // 30 seconds between scans
});

モニタリングと範囲指定のためにビーコン リージョンを定義します。

export interface BeaconRegion {
/**
* Unique identifier for this region.
*/
identifier: string;
/**
* UUID of the beacon(s) to detect.
*/
uuid: string;
/**
* Major value for filtering (optional).
*/
major?: number;
/**
* Minor value for filtering (optional).
*/
minor?: number;
/**
* Notify when device enters region (iOS only).
*/
notifyEntryStateOnDisplay?: boolean;
/**
* Enable Android background mode for this monitoring/ranging call.
* When true, the plugin will keep scanning in background using a foreground service.
*/
enableBackgroundMode?: boolean;
}

iBeacon (iOSのみ)として送信するビーコン広告オプション。

export interface BeaconAdvertisingOptions {
/**
* UUID to advertise.
*/
uuid: string;
/**
* Major value (0-65535).
*/
major: number;
/**
* Minor value (0-65535).
*/
minor: number;
/**
* Identifier for the advertising beacon.
*/
identifier: string;
/**
* Measured power (RSSI at 1 meter). Optional, defaults to -59.
*/
measuredPower?: number;
}

バックグラウンドスキャン期間の設定オプション (Androidのみ)。

export interface BackgroundScanPeriodOptions {
/**
* Duration of each scan period in milliseconds.
* Default: 10000 (10 seconds)
*/
scanPeriod?: number;
/**
* Duration between scan periods in milliseconds.
* Default: 15000 (15 seconds)
*/
betweenScanPeriod?: number;
}

ビーコンが範囲内に入ったときのイベントデータ。

export interface RangingEventData {
/**
* Region that was ranged.
*/
region: BeaconRegion;
/**
* Array of detected beacons.
*/
beacons: Beacon[];
}

地域に入ったり出たりするときのイベントデータ。

export interface MonitoringEventData {
/**
* Region that triggered the event.
*/
region: BeaconRegion;
/**
* Event state: 'enter' or 'exit'.
*/
state: 'enter' | 'exit';
}

ビーコン情報が検出されました。

export interface Beacon {
/**
* Beacon UUID.
*/
uuid: string;
/**
* Major value.
*/
major: number;
/**
* Minor value.
*/
minor: number;
/**
* RSSI (Received Signal Strength Indicator).
*/
rssi: number;
/**
* Proximity: 'immediate', 'near', 'far', or 'unknown'.
*/
proximity: 'immediate' | 'near' | 'far' | 'unknown';
/**
* Estimated distance in meters.
*/
accuracy: number;
}

このページはプラグインの src/definitions.tsAPI のパブリックがアップストリームで変更されたら、再度 Sync を実行してください。

あなたが「Capgo」を使用している場合 Getting Started ダッシュボードとAPIの運用計画を立てるには、 Using @capgo/capacitor-ibeacon Using @capgo/capacitor-ibeaconのネイティブ機能 APIの概要 APIの概要の実装詳細 導入 導入の実装詳細 APIのキー APIのキーに関する実装詳細 デバイス デバイスに関する実装詳細