快速入门
复制包含安装步骤和该插件完整 Markdown 指南的配置 prompt。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-pedometer`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/pedometer/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
“安装”章节你可以使用我们的 AI 辅助设置来安装插件。使用以下命令将 Capgo skills 添加到你的 AI 工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下 prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-pedometer` plugin in my project.如果你更想手动设置,请运行以下命令安装插件,并按照下方各平台的说明操作:
bun add @capgo/capacitor-pedometerbunx 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);});示例:查询 iOS 历史记录
章节标题:“示例:iOS 历史查询”const sample = await CapacitorPedometer.getMeasurement({ startDate: start.toISOString(), endDate: end.toISOString(),});常见坑点
章节标题为“常见陷阱”- 权限:iOS 上的运动数据,
ACTIVITY_RECOGNITION在 Android 上。 - Web 端:不可用,在 Web 构建中隐藏步数 UI。
- 停止更新: 调用
stopMeasurementUpdates()以节省电量。
API 概览
章节标题:“API 概览”getMeasurement
“getMeasurement” 部分获取指定时间范围内的计步器测量数据。
import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
const result = await CapacitorPedometer.getMeasurement();console.log(result);isAvailable
标题为 “isAvailable” 的章节检查此设备上可用的计步器功能。
import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
const result = await CapacitorPedometer.isAvailable();console.log(result);startMeasurementUpdates
标题为 “startMeasurementUpdates” 的章节开始接收实时计步器测量更新。
当 Android 以及 iOS, measurement 事件仅在调用后触发 startMeasurementUpdates().
import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
await CapacitorPedometer.startMeasurementUpdates();stopMeasurementUpdates
标题为 “stopMeasurementUpdates” 的章节停止接收实时的计步器测量更新。
import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
await CapacitorPedometer.stopMeasurementUpdates();checkPermissions
“checkPermissions” 章节检查访问计步器数据的权限。
当 Android,这会检查 ACTIVITY_RECOGNITION 权限。
在 iOS,这会检查运动使用权限。
import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
const result = await CapacitorPedometer.checkPermissions();console.log(result);requestPermissions
“requestPermissions” 章节请求访问计步器数据的权限。
当 Android,这会请求 ACTIVITY_RECOGNITION 权限。
在 iOS,此操作将请求运动使用权限。
import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
const result = await CapacitorPedometer.requestPermissions();console.log(result);类型参考
“类型参考” 章节GetMeasurementOptions
标题为“GetMeasurementOptions”的章节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;}Measurement
标题为“Measurement”的章节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;}IsAvailableResult
标题为“IsAvailableResult”的章节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;}PermissionStatus
标题为“PermissionStatus”的章节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';}MeasurementEvent
标题为“MeasurementEvent”的章节export type MeasurementEvent = Measurement;单一事实来源
标题为“单一事实来源”的部分本页面由插件的 src/definitions.ts生成。当上游的公共 API 发生变化时,请重新运行 sync。
从入门指南继续
“从入门指南继续”章节如果你正在使用 快速入门 要规划 dashboard 和 API 操作,请将其连接到 使用 @capgo/capacitor-pedometer 关于使用 @capgo/capacitor-pedometer 中的原生能力, API 概览 关于 API Overview 中的实现细节, 简介 关于 Introduction 中的实现细节, API 密钥 有关 API Keys 的实现细节,以及 设备 有关 Devices 的实现细节。