An open API service indexing awesome lists of open source software.

https://github.com/Cap-go/capacitor-barometer

Capacitor plugin to read device barometer
https://github.com/Cap-go/capacitor-barometer

Last synced: about 1 month ago
JSON representation

Capacitor plugin to read device barometer

Awesome Lists containing this project

README

          

# @capgo/capacitor-barometer
Capgo - Instant updates for capacitor


➡️ Get Instant updates for your App with Capgo


Missing a feature? We’ll build the plugin for you 💪


Access barometer pressure measurements across iOS and Android.

## Documentation

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

## Compatibility

| Plugin version | Capacitor compatibility | Maintained |
| -------------- | ----------------------- | ---------- |
| 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

```bash
npm install @capgo/capacitor-barometer
npx cap sync
```

## API

* [`getMeasurement()`](#getmeasurement)
* [`isAvailable()`](#isavailable)
* [`startMeasurementUpdates()`](#startmeasurementupdates)
* [`stopMeasurementUpdates()`](#stopmeasurementupdates)
* [`checkPermissions()`](#checkpermissions)
* [`requestPermissions()`](#requestpermissions)
* [`addListener('measurement', ...)`](#addlistenermeasurement-)
* [`removeAllListeners()`](#removealllisteners)
* [`getPluginVersion()`](#getpluginversion)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)

Capacitor plugin contract for working with the device barometer sensor.

### getMeasurement()

```typescript
getMeasurement() => Promise
```

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

**Returns:** Promise<Measurement>

**Since:** 1.0.0

--------------------

### isAvailable()

```typescript
isAvailable() => Promise
```

Check if the current device includes a barometer sensor.

**Returns:** Promise<IsAvailableResult>

**Since:** 1.0.0

--------------------

### startMeasurementUpdates()

```typescript
startMeasurementUpdates() => Promise
```

Begin streaming barometer updates to the JavaScript layer.

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

**Since:** 1.0.0

--------------------

### stopMeasurementUpdates()

```typescript
stopMeasurementUpdates() => Promise
```

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

**Since:** 1.0.0

--------------------

### checkPermissions()

```typescript
checkPermissions() => Promise
```

Return the current permission state for accessing barometer data.

**Returns:** Promise<PermissionStatus>

**Since:** 1.0.0

--------------------

### requestPermissions()

```typescript
requestPermissions() => Promise
```

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

**Returns:** Promise<PermissionStatus>

**Since:** 1.0.0

--------------------

### addListener('measurement', ...)

```typescript
addListener(eventName: 'measurement', listenerFunc: (event: MeasurementEvent) => void) => Promise
```

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()

```typescript
removeAllListeners() => Promise
```

Remove all registered listeners for this plugin.

**Since:** 1.0.0

--------------------

### getPluginVersion()

```typescript
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