@capgo/capacitor-pedometer

中文文档
8.0.54发布于 2026/11/09MPL-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 5.3万

Capacitor plugin for accessing pedometer data including steps, distance, pace, cadence, and floors

原始使用文档
文档目录23 节
  1. ➡️ Get started for free
  2. Key features
  3. Compatibility
  4. Install
  5. Configuration
  6. iOS
  7. Android
  8. API
  9. getMeasurement(...)
  10. isAvailable()
  11. startMeasurementUpdates()
  12. stopMeasurementUpdates()
  13. checkPermissions()
  14. requestPermissions()
  15. addListener('measurement', ...)
  16. removeAllListeners()
  17. getPluginVersion()
  18. Interfaces
  19. Type Aliases
  20. Usage
  21. Platform Support
  22. Notes
  23. License

@capgo/capacitor-pedometer

Count steps in your Capacitor app with the device motion sensors: live step updates and history queries for fitness, health and challenge apps.

Capgo - Build Capacitor apps with AI, ship updates instantly

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

➡️ Get started for free

14-day unlimited free trial. No credit card required

🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-pedometer in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-pedometer to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

@capgo/capacitor-pedometer for Capacitor apps

Key features

  • Live updates: startMeasurementUpdates() streams the measurement event, stopMeasurementUpdates() ends it.
  • History on iOS: getMeasurement() returns steps for a time range.
  • Rich data on iOS: distance, pace, cadence and floors ascended or descended from Core Motion.
  • Availability: isAvailable() tells you which metrics the device supports.
  • Permissions: motion permission on iOS and ACTIVITY_RECOGNITION on Android.
  • Platforms: iOS and Android. Android counts steps with the step sensor. Not available on web.

Compatibility

Plugin versionCapacitor compatibilityMaintained
v8.*.*v8.*.*✅
v7.*.*v7.*.*On demand
v6.*.*v6.*.*❌
v5.*.*v5.*.*❌

Note: The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.

Install

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

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

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capgo/capacitor-pedometer
npx cap sync

Configuration

iOS

Add the following to your Info.plist:

<key>NSMotionUsageDescription</key>
<string>We need access to your motion data to track steps and activity</string>

Android

The plugin will automatically add the ACTIVITY_RECOGNITION permission to your AndroidManifest.xml.

For Android 10 (API 29) and above, you need to request the ACTIVITY_RECOGNITION permission at runtime.

API

getMeasurement(...)

getMeasurement(options?: GetMeasurementOptions | undefined) => Promise<Measurement>

Get pedometer measurements for a specified time range.

ParamType
optionsGetMeasurementOptions

Returns: Promise<Measurement>

Since: 0.0.1


isAvailable()

isAvailable() => Promise<IsAvailableResult>

Check which pedometer features are available on this device.

Returns: Promise<IsAvailableResult>

Since: 0.0.1


startMeasurementUpdates()

startMeasurementUpdates() => Promise<void>

Start receiving real-time pedometer measurement updates.

On Android and iOS, the measurement event is only fired after calling startMeasurementUpdates().

Since: 0.0.1


stopMeasurementUpdates()

stopMeasurementUpdates() => Promise<void>

Stop receiving real-time pedometer measurement updates.

Since: 0.0.1


checkPermissions()

checkPermissions() => Promise<PermissionStatus>

Check permission to access pedometer data.

On Android, this checks the ACTIVITY_RECOGNITION permission. On iOS, this checks the motion usage permission.

Returns: Promise<PermissionStatus>

Since: 0.0.1


requestPermissions()

requestPermissions() => Promise<PermissionStatus>

Request permission to access pedometer data.

On Android, this requests the ACTIVITY_RECOGNITION permission. On iOS, this requests motion usage permission.

Returns: Promise<PermissionStatus>

Since: 0.0.1


addListener('measurement', ...)

addListener(eventName: 'measurement', listenerFunc: (event: MeasurementEvent) => void) => Promise<PluginListenerHandle>

Called when a new pedometer measurement is received.

ParamType
eventName'measurement'
listenerFunc(event: Measurement) => void

Returns: Promise<PluginListenerHandle>

Since: 0.0.1


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all listeners for this plugin.

Since: 0.0.1


getPluginVersion()

getPluginVersion() => Promise<{ version: string; }>

Get the native Capacitor plugin version.

Returns: Promise<{ version: string; }>

Since: 1.0.0


Interfaces

Measurement

PropTypeDescriptionSince
numberOfStepsnumberThe number of steps taken by the user.0.0.1
distancenumberThe estimated distance (in meters) traveled by the user. Only available on iOS.0.0.1
floorsAscendednumberThe approximate number of floors ascended. Only available on iOS.0.0.1
floorsDescendednumberThe approximate number of floors descended. Only available on iOS.0.0.1
currentPacenumberThe current pace (in seconds per meter). Only available on iOS.0.0.1
currentCadencenumberThe current cadence (steps per second). Only available on iOS.0.0.1
averageActivePacenumberThe average active pace (in seconds per meter). Only available on iOS.0.0.1
startDatenumberThe start time of this measurement (milliseconds since epoch).0.0.1
endDatenumberThe end time of this measurement (milliseconds since epoch).0.0.1

GetMeasurementOptions

PropTypeDescriptionSince
startnumberThe start time for the measurement query (milliseconds since epoch). Required on iOS.0.0.1
endnumberThe end time for the measurement query (milliseconds since epoch). Required on iOS.0.0.1

IsAvailableResult

PropTypeDescriptionSince
stepCountingbooleanWhether step counting is available.0.0.1
distancebooleanWhether distance measurement is available. Only true on iOS devices that support distance tracking.0.0.1
pacebooleanWhether pace measurement is available. Only true on iOS devices that support pace tracking.0.0.1
cadencebooleanWhether cadence measurement is available. Only true on iOS devices that support cadence tracking.0.0.1
floorCountingbooleanWhether floor counting is available. Only true on iOS devices that support floor tracking.0.0.1

PermissionStatus

PropTypeDescriptionSince
activityRecognition'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'Permission state for activity recognition. On Android, this is the ACTIVITY_RECOGNITION permission. On iOS, this is the motion usage permission.0.0.1

PluginListenerHandle

PropType
remove() => Promise<void>

Type Aliases

MeasurementEvent

Measurement

Usage

import { CapacitorPedometer } from '@capgo/capacitor-pedometer';

// Check availability
const availability = await CapacitorPedometer.isAvailable();
console.log('Features available:', availability);

// Check and request permissions
const permission = await CapacitorPedometer.checkPermissions();
if (permission.activityRecognition !== 'granted') {
  await CapacitorPedometer.requestPermissions();
}

// Start real-time updates
await CapacitorPedometer.addListener('measurement', (data) => {
  console.log('Steps:', data.numberOfSteps);
  console.log('Distance:', data.distance);
});

await CapacitorPedometer.startMeasurementUpdates();

// Query historical data (iOS only - requires start and end timestamps)
const now = Date.now();
const yesterday = now - (24 * 60 * 60 * 1000);
const measurement = await CapacitorPedometer.getMeasurement({
  start: yesterday,
  end: now
});

// Stop updates
await CapacitorPedometer.stopMeasurementUpdates();
await CapacitorPedometer.removeAllListeners();

Platform Support

FeatureAndroidiOS
Step Counting✅✅
Distance❌✅
Pace❌✅
Cadence❌✅
Floor Counting❌✅
Historical Queries❌✅

Notes

  • On Android, only step counting is available. The plugin uses the TYPE_STEP_COUNTER sensor.
  • On iOS, all features are available on supported devices using CMPedometer.
  • Historical data queries require explicit start and end timestamps on iOS.
  • Android's step counter gives cumulative steps since last device reboot; the plugin tracks the delta.
  • Measurements are paused when the app is in the background.

License

MIT

版本与发布记录

@capgo/capacitor-pedometer 共发布 60 个版本,首次发布于 2025/10/27;过去 12 个月发布了 55 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.0.54latest2026/11/09今天
8.0.532026/11/026 天前
8.0.522026/10/2613 天前
8.0.512026/10/1920 天前
8.0.502026/10/1525 天前
8.0.492026/10/1327 天前

关于 @capgo/capacitor-pedometer 的常见问题

@capgo/capacitor-pedometer 是什么?

Capacitor plugin for accessing pedometer data including steps, distance, pace, cadence, and floors

如何安装 @capgo/capacitor-pedometer?

在项目目录运行 npm install @capgo/capacitor-pedometer,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capgo/capacitor-pedometer 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capgo/capacitor-pedometer 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capgo/capacitor-pedometer 可以商用吗?

@capgo/capacitor-pedometer 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@capgo/capacitor-pedometer 的下载量有多少?

根据 npm 官方下载统计,@capgo/capacitor-pedometer 在 2026/10/09 – 2026/11/07 这 30 天内被下载 52,611 次,日均约 1,754 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capgo/capacitor-pedometer 还在维护吗?

最新版本 8.0.54 发布于 2026/11/09(今天);至今共发布 60 个版本,其中过去 12 个月发布了 55 个;首次发布于 2025/10/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。