开始
复制一个包含安装步骤和本插件完整 Markdown 指南的设置提示。
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 技能添加到您的 AI 工具中,使用以下命令:
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-pedometerbunx cap sync导入
导入import { CapacitorPedometer } from '@capgo/capacitor-pedometer';API 概述
API 概述getMeasurement
获取测量值获取指定时间范围内的步数计数器测量值。
import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
const result = await CapacitorPedometer.getMeasurement();console.log(result);isAvailable
步数计数器功能是否可用检查设备上哪些步数计数器功能可用
import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
const result = await CapacitorPedometer.isAvailable();console.log(result);startMeasurementUpdates
开始测量更新实时接收步数计数测量数据。
开启 Android 和 iOS, measurement 事件只在调用 startMeasurementUpdates().
import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
await CapacitorPedometer.startMeasurementUpdates();stopMeasurementUpdates
停止测量更新停止实时接收步数计数测量数据。
import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
await CapacitorPedometer.stopMeasurementUpdates();checkPermissions
检查权限获取步数计数器数据的权限。
On Android, 这会检查 ACTIVITY_RECOGNITION 权限。
On iOS, 这会检查运动使用权限。
import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
const result = await CapacitorPedometer.checkPermissions();console.log(result);requestPermissions
请求权限请求获取步数计数器数据的权限。
On Android, 这个请求需要 ACTIVITY_RECOGNITION 权限。
在 iOS, 这个请求需要运动使用权限。
import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
const result = await CapacitorPedometer.requestPermissions();console.log(result);类型参考
标题:类型参考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
标题:测量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
IsAvailableResultexport 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
权限状态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
测量事件export type MeasurementEvent = Measurement;本页面是由插件生成的 src/definitions.ts当公共 API 在上游发生变化时,请重新运行同步。
继续从 Getting Started
Section titled “继续从 Getting Started”如果您正在使用 开始使用 为了规划仪表盘和API操作,连接它 使用 @capgo/capacitor-pedometer for the native capability in 使用 @capgo/capacitor-pedometer API 简介 for the implementation detail in API Overview 介绍 for the implementation detail in 介绍 API 键 为API中的实现细节提供。 设备 为设备的实现细节。