Skip to content

About

Capacitor plugin to read device barometer

Resources

Code of conduct

Contributing

Security policy

Stars

8 stars

Watchers

1 watching

Forks

@capgo/capacitor-barometer

Read air pressure from the device barometer on iOS and Android, as the latest sample or as a live stream of updates. Weather, outdoor and fitness apps get real sensor data with a few lines of code.

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.

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-barometer in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-barometer to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

Capgo barometer plugin for Capacitor: npm i @capgo/capacitor-barometer

Built and maintained with AI

We build, improve and fix our plugins with heavy use of AI, so issues usually get fixed in under a day and pull requests get feedback the same day. A human still reviews, tests and merges 50+ pull requests daily.

  • Most plugin issues get a fix pull request the same day, often within a couple of hours, and are usually resolved in one to two days.
  • Every pull request goes through our AI review system, usually within minutes.
  • Our AI pre-checks tests, code review, conventions and security, then a human reviews, tests and merges.
  • A human, Martin, reviews, tests and merges 50+ pull requests every day.
  • In the last 90 days, 95% of plugin issues were resolved.

Learn more about how we build with AI

Key features

  • Pressure readings: getMeasurement() returns the latest air pressure sample in hectopascals (hPa) with a timestamp. Start updates first, since it returns 0 until the first sensor event.
  • Live updates: startMeasurementUpdates() streams readings to the measurement listener until you call stopMeasurementUpdates().
  • Relative altitude on iOS: each reading includes the altitude change since updates started (Android reports 0).
  • Availability check: isAvailable() tells you whether the device has a barometer before you show pressure UI.
  • Permission status: checkPermissions() and requestPermissions() report access, using Core Motion authorization on iOS 17 and later.
  • Platforms: iOS and Android. iOS uses Core Motion CMAltimeter, Android uses Sensor.TYPE_PRESSURE. On web, isAvailable() returns false.

Documentation

The most complete doc is available here: https://capgo.app/docs/plugins/barometer/

Compatibility

Plugin version Capacitor compatibility Maintained
v9.*.* v9.*.* ✅
v8.*.* v8.*.* On demand
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 v9 for Capacitor 9). Only the latest major version is actively maintained.

Migrating from v8 to v9

v9 of @capgo/capacitor-barometer targets Capacitor 9. Update Capacitor and this plugin together, then sync the native projects:

npm install @capacitor/core@^9.0.0 @capacitor/cli@^9.0.0 @capacitor/ios@^9.0.0 @capacitor/android@^9.0.0 @capgo/capacitor-barometer@^9.0.0
npx cap sync

Capacitor 9 needs Node.js 24+, iOS 16+ (Xcode 27) and Android minSdk 26 / compileSdk 37. Follow the official Capacitor 9 update guide for the app side changes.

No plugin API was removed: the JavaScript API of v9 is the same as v8.

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-barometer` 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-barometer
npx cap sync

API

Capacitor plugin contract for working with the device barometer sensor.

getMeasurement()

getMeasurement() => Promise<GetMeasurementResult>

Get the most recent barometer reading captured by the native layer.

Returns: Promise<Measurement>

Since: 1.0.0


isAvailable()

isAvailable() => Promise<IsAvailableResult>

Check if the current device includes a barometer sensor.

Returns: Promise<IsAvailableResult>

Since: 1.0.0


startMeasurementUpdates()

startMeasurementUpdates() => Promise<void>

Begin streaming barometer updates to the JavaScript layer.

Call {@link addListener} with the measurement event to receive the updates.

Since: 1.0.0


stopMeasurementUpdates()

stopMeasurementUpdates() => Promise<void>

Stop the continuous updates started via {@link startMeasurementUpdates}.

Since: 1.0.0


checkPermissions()

checkPermissions() => Promise<PermissionStatus>

Return the current permission state for accessing barometer data.

Returns: Promise<PermissionStatus>

Since: 1.0.0


requestPermissions()

requestPermissions() => Promise<PermissionStatus>

Request permission to access barometer data if required by the platform.

Returns: Promise<PermissionStatus>

Since: 1.0.0


addListener('measurement', ...)

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

Listen for pressure updates.

Param Type Description
eventName 'measurement' Only the measurement event is supported.
listenerFunc (event: Measurement) => void Callback invoked with each measurement.

Returns: Promise<PluginListenerHandle>

Since: 1.0.0


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all registered listeners for this plugin.

Since: 1.0.0


getPluginVersion()

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

Get the native Capacitor plugin version.

Returns: Promise<{ version: string; }>

Since: 1.0.0


Interfaces

Measurement

Air pressure and relative altitude values sampled from the device barometer.

Prop Type Description Since
pressure number The static air pressure in hectopascals (hPa). 1.0.0
relativeAltitude number The change in altitude relative to the time updates started. Only available on iOS; Android will always return 0. 1.0.0
timestamp number The timestamp of the measurement in milliseconds since the Unix epoch. 1.0.0

IsAvailableResult

Result returned by {@link CapacitorBarometerPlugin.isAvailable}.

Prop Type Description Since
isAvailable boolean Indicates whether the device exposes a barometer sensor. 1.0.0

PermissionStatus

Permission information returned by {@link CapacitorBarometerPlugin.checkPermissions} and {@link CapacitorBarometerPlugin.requestPermissions}.

Prop Type Description Since
barometer BarometerPermissionState The permission state for accessing barometer measurements on the current platform. 1.0.0

PluginListenerHandle

Prop Type
remove () => Promise<void>

Type Aliases

GetMeasurementResult

Alias for the most recent pressure sample.

Measurement

BarometerPermissionState

Permission state union including limited for platforms that can throttle sensor access.

PermissionState | 'limited'

PermissionState

'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'

MeasurementEvent

Event payload emitted when {@link CapacitorBarometerPlugin.startMeasurementUpdates} is active.

Measurement

Credit

This plugin was inspired from: https://github.com/kesha-antonov/react-native-background-downloader

About

Capacitor plugin to read device barometer

Resources

Code of conduct

Contributing

Security policy

Stars

8 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages