@capawesome-team/capacitor-barometer¶
Capacitor plugin to obtain the static air pressure, which is measured in hectopascals (hPa).
Features¶
We are proud to offer one of the most complete and feature-rich Capacitor plugins for barometer measurements. Here are some of the key features:
- 🖥️ Cross-platform: Supports Android and iOS.
 - 📏 Precise Measurements: Get accurate air pressure readings in hectopascals (hPa).
 - 🔄 Real-time Updates: Continuously monitor barometer changes with event listeners.
 - 🔍 Device Detection: Check if barometer sensor is available on the device.
 - 🔑 Permissions: Check and request barometer sensor permissions.
 - 📊 Additional Data: Get relative altitude measurements.
 - ⏱️ Timestamps: Each measurement includes precise timing information.
 - 📦 SPM: Supports Swift Package Manager for iOS.
 - 🔁 Up-to-date: Always supports the latest Capacitor version.
 - ⭐️ Support: Priority support from the Capawesome Team.
 - ✨ Handcrafted: Built from the ground up with care and expertise, not forked or AI-generated.
 
Missing a feature? Just open an issue and we'll take a look!
Compatibility¶
| Plugin Version | Capacitor Version | Status | 
|---|---|---|
| 7.x.x | >=7.x.x | Active support | 
Guides¶
Installation¶
This plugin is only available to Capawesome Insiders. First, make sure you have the Capawesome npm registry set up. You can do this by running the following commands:
npm config set @capawesome-team:registry https://npm.registry.capawesome.io
npm config set //npm.registry.capawesome.io/:_authToken <YOUR_LICENSE_KEY>
Attention: Replace <YOUR_LICENSE_KEY> with the license key you received from Polar. If you don't have a license key yet, you can get one by becoming a Capawesome Insider.
Next, install the package:
Android¶
Proguard¶
If you are using Proguard, you need to add the following rules to your proguard-rules.pro file:
iOS¶
Privacy Descriptions¶
Add the NSMotionUsageDescription key to the ios/App/App/Info.plist file, which tells the user why your app needs access to the user's contacts:
Usage¶
import { Barometer } from '@capawesome-team/capacitor-barometer';
const getMeasurement = async () => {
  const { measurement } = await Barometer.getMeasurement();
  console.log('Pressure:', measurement.pressure, 'hPa');
  console.log('Relative Altitude:', measurement.relativeAltitude, 'm');
  console.log('Timestamp:', new Date(measurement.timestamp));
};
const isAvailable = async () => {
  const result = await Barometer.isAvailable();
  console.log('Barometer is available:', result.isAvailable);
};
const startMeasurementUpdates = async () => {
  Barometer.addListener('measurement', (event) => {
    console.log('New measurement:', event);
  });
  await Barometer.startMeasurementUpdates();
};
const stopMeasurementUpdates = async () => {
  await Barometer.stopMeasurementUpdates();
  Barometer.removeAllListeners();
};
const checkPermissions = async () => {
  const status = await Barometer.checkPermissions();
  console.log('Barometer permission status:', status.barometer);
};
const requestPermissions = async () => {
  const status = await Barometer.requestPermissions();
  console.log('Barometer permission status after request:', status.barometer);
};
API¶
getMeasurement()isAvailable()startMeasurementUpdates()stopMeasurementUpdates()checkPermissions()requestPermissions()addListener('measurement', ...)removeAllListeners()- Interfaces
 - Type Aliases
 
getMeasurement()¶
Get the latest measurement.
This method returns the most recent measurement from the barometer sensor.
Only available on Android and iOS.
Returns: Promise<Measurement>
Since: 7.0.0
isAvailable()¶
Check if the barometer sensor is available on the device.
Returns: Promise<IsAvailableResult>
Since: 7.0.0
startMeasurementUpdates()¶
Starts emitting measurement events.
Only available on Android and iOS.
Since: 7.0.0
stopMeasurementUpdates()¶
Stops emitting measurement events.
Only available on Android and iOS.
Since: 7.0.0
checkPermissions()¶
Check if the app has permission to access the barometer sensor.
Only available on Android and iOS.
Returns: Promise<PermissionStatus>
Since: 7.0.0
requestPermissions()¶
Request permission to access the barometer sensor.
Only available on Android and iOS.
Returns: Promise<PermissionStatus>
Since: 7.0.0
addListener('measurement', ...)¶
addListener(eventName: 'measurement', listenerFunc: (event: MeasurementEvent) => void) => Promise<PluginListenerHandle>
Only available on Android and iOS.
| Param | Type | 
|---|---|
eventName | 
'measurement' | 
listenerFunc | 
(event: Measurement) => void | 
Returns: Promise<PluginListenerHandle>
Since: 7.0.0
removeAllListeners()¶
Remove all listeners for this plugin.
Since: 7.0.0
Interfaces¶
Measurement¶
| Prop | Type | Description | Since | 
|---|---|---|---|
pressure | 
number | 
The pressure in hPa (hectopascal). | 7.0.0 | 
relativeAltitude | 
number | 
The relative altitude in meters. Only available on iOS. | 7.0.0 | 
timestamp | 
number | 
The timestamp of the measurement in milliseconds since the epoch. | 7.0.0 | 
IsAvailableResult¶
| Prop | Type | Description | Since | 
|---|---|---|---|
isAvailable | 
boolean | 
Indicates whether the barometer sensor is available on the device. | 7.0.0 | 
PermissionStatus¶
| Prop | Type | Description | Since | 
|---|---|---|---|
barometer | 
BarometerPermissionState | 
The permission status of barometer. | 7.0.0 | 
PluginListenerHandle¶
| Prop | Type | 
|---|---|
remove | 
() => Promise<void> | 
Type Aliases¶
GetMeasurementResult¶
BarometerPermissionState¶
PermissionState | 'limited'
PermissionState¶
'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'
MeasurementEvent¶
Changelog¶
See CHANGELOG.md.
Breaking Changes¶
See BREAKING.md.
License¶
See LICENSE.