メインコンテンツへスキップ

スタートガイド

GitHub

AIアシストによるセットアップでプラグインをインストールできます。以下のコマンドを使用して、お使いのAIツールに Capgo のスキルを追加してください:

ターミナル
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

次に、以下のプロンプトを使用します:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-pedometer` plugin in my project.

手動セットアップを希望する場合は、以下のコマンドを実行してプラグインをインストールし、下記のプラットフォーム別の手順に従ってください:

ターミナル
bun add @capgo/capacitor-pedometer
bunx cap sync
import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
await CapacitorPedometer.requestPermissions();
await CapacitorPedometer.startMeasurementUpdates();
await CapacitorPedometer.addListener('measurement', (event) => {
updateStepCount(event.numberOfSteps);
});
const sample = await CapacitorPedometer.getMeasurement({
startDate: start.toISOString(),
endDate: end.toISOString(),
});
  • 権限: iOS のモーション, ACTIVITY_RECOGNITION Androidの場合
  • Web:利用不可。Web ビルドではステップ UI を非表示にします。
  • 更新を停止:呼び出し stopMeasurementUpdates() バッテリーの節約に。

指定した時間範囲の歩数計測値を取得します。

import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
const result = await CapacitorPedometer.getMeasurement();
console.log(result);

このデバイスで利用可能な歩数計機能をチェックします。

import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
const result = await CapacitorPedometer.isAvailable();
console.log(result);

リアルタイムの歩数計測更新の受信を開始します。

オンラインに Androidでは と iOSとこの measurement イベントは呼び出した後にのみ発火します startMeasurementUpdates().

import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
await CapacitorPedometer.startMeasurementUpdates();

歩数計のリアルタイム測定更新の受信を停止します。

import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
await CapacitorPedometer.stopMeasurementUpdates();

歩数計データへのアクセス権限を確認します。

オンラインに Androidでは、これは ACTIVITY_RECOGNITION 権限を確認します。 オン iOSと、これはモーション使用権限を確認します。

import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
const result = await CapacitorPedometer.checkPermissions();
console.log(result);

歩数計データへのアクセス権限をリクエストします。

オンラインに Androidでは、これは ACTIVITY_RECOGNITION 権限を確認します。 オン iOSと、これによりモーション使用の許可を要求します。

import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
const result = await CapacitorPedometer.requestPermissions();
console.log(result);
export interface GetMeasurementOptions {
/**
* The start time for the measurement query (milliseconds since epoch).
*
* Required on **iOS**.
*
* @since 0.0.1
*/
start?: number;
/**
* The end time for the measurement query (milliseconds since epoch).
*
* Required on **iOS**.
*
* @since 0.0.1
*/
end?: number;
}
export interface Measurement {
/**
* The number of steps taken by the user.
*
* @since 0.0.1
*/
numberOfSteps?: number;
/**
* The estimated distance (in meters) traveled by the user.
*
* Only available on **iOS**.
*
* @since 0.0.1
*/
distance?: number;
/**
* The approximate number of floors ascended.
*
* Only available on **iOS**.
*
* @since 0.0.1
*/
floorsAscended?: number;
/**
* The approximate number of floors descended.
*
* Only available on **iOS**.
*
* @since 0.0.1
*/
floorsDescended?: number;
/**
* The current pace (in seconds per meter).
*
* Only available on **iOS**.
*
* @since 0.0.1
*/
currentPace?: number;
/**
* The current cadence (steps per second).
*
* Only available on **iOS**.
*
* @since 0.0.1
*/
currentCadence?: number;
/**
* The average active pace (in seconds per meter).
*
* Only available on **iOS**.
*
* @since 0.0.1
*/
averageActivePace?: number;
/**
* The start time of this measurement (milliseconds since epoch).
*
* @since 0.0.1
*/
startDate?: number;
/**
* The end time of this measurement (milliseconds since epoch).
*
* @since 0.0.1
*/
endDate?: number;
}
export interface IsAvailableResult {
/**
* Whether step counting is available.
*
* @since 0.0.1
*/
stepCounting: boolean;
/**
* Whether distance measurement is available.
*
* Only `true` on **iOS** devices that support distance tracking.
*
* @since 0.0.1
*/
distance: boolean;
/**
* Whether pace measurement is available.
*
* Only `true` on **iOS** devices that support pace tracking.
*
* @since 0.0.1
*/
pace: boolean;
/**
* Whether cadence measurement is available.
*
* Only `true` on **iOS** devices that support cadence tracking.
*
* @since 0.0.1
*/
cadence: boolean;
/**
* Whether floor counting is available.
*
* Only `true` on **iOS** devices that support floor tracking.
*
* @since 0.0.1
*/
floorCounting: boolean;
}
export interface PermissionStatus {
/**
* Permission state for activity recognition.
*
* On **Android**, this is the `ACTIVITY_RECOGNITION` permission.
* On **iOS**, this is the motion usage permission.
*
* @since 0.0.1
*/
activityRecognition: 'prompt' | 'prompt-with-rationale' | 'granted' | 'denied';
}
export type MeasurementEvent = Measurement;

このページはプラグインの src/definitions.tsから生成されています。upstream で公開 API が変更されたら、再度 sync を実行してください。

Getting Startedの続きを進める

「Getting Started からの続き」セクション

使用している場合 スタートガイド ダッシュボードと API の運用を計画するには、これを次と連携させます @capgo/capacitor-pedometer の使い方 「@capgo/capacitor-pedometer」のネイティブ機能を使用する際の API の概要 「API の概要」の実装の詳細については、 はじめに 「はじめに」における実装の詳細については、 API キー および「API Keys」の実装の詳細については、 デバイス 実装の詳細については Devices を参照してください。