Skip to main content
@capgo/capacitor-health Device APIs Open source

Health Capacitor plugin

Access health and fitness data from native health platforms

Install

bun add @capgo/capacitor-health bunx cap sync
npm, pnpm or yarn
  • npm install @capgo/capacitor-health
  • pnpm add @capgo/capacitor-health
  • yarn add @capgo/capacitor-health

Guide

How to use Health in Capacitor

Using @capgo/capacitor-health

Capacitor plugin to interact with data from Apple HealthKit and Health Connect.

Install

bun add @capgo/capacitor-health
bunx cap sync

bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.

Import

import { Health } from '@capgo/capacitor-health';

API at a glance

Method Description
isAvailable Returns whether the current platform supports the native health SDK.
requestAuthorization Requests read/write access to the provided data types.
checkAuthorization Checks authorization status for the provided data types without prompting the user.
readSamples Reads samples for the given data type within the specified time frame.
saveSample Writes a single sample to the native health store.
openHealthConnectSettings Opens the Health Connect settings screen (Android only). On iOS, this method does nothing.
showPrivacyPolicy Shows the app's privacy policy for Health Connect (Android only). On iOS, this method does nothing.
queryWorkouts Queries workout sessions from the native health store. Supported on iOS (HealthKit) and Android (Health Connect).
queryAggregated Queries aggregated health data from the native health store. Aggregates data into time buckets (hour, day, week, month) with operations like sum, average, min, or max. This is more efficient than fetching individual samples for large date ranges.

Examples

isAvailable()

Returns whether the current platform supports the native health SDK.

import { Health } from '@capgo/capacitor-health';

const result = await Health.isAvailable();
console.log(result);

requestAuthorization()

Requests read/write access to the provided data types.

import { Health } from '@capgo/capacitor-health';

const result = await Health.requestAuthorization({ read: ['steps'] });
console.log(result);

checkAuthorization()

Checks authorization status for the provided data types without prompting the user.

import { Health } from '@capgo/capacitor-health';

const result = await Health.checkAuthorization({ read: ['steps'] });
console.log(result);

readSamples()

Reads samples for the given data type within the specified time frame.

import { Health } from '@capgo/capacitor-health';

const result = await Health.readSamples({ dataType: 'steps' });
console.log(result);

saveSample()

Writes a single sample to the native health store.

import { Health } from '@capgo/capacitor-health';

await Health.saveSample({
  dataType: 'steps',
  value: 1,
});

openHealthConnectSettings()

Opens the Health Connect settings screen (Android only). On iOS, this method does nothing.

import { Health } from '@capgo/capacitor-health';

await Health.openHealthConnectSettings();

The table above lists the 9 core methods. Listener and version helpers, and the full contract of each method, are documented in the GitHub repository.

Full reference

Keep going from Using @capgo/capacitor-health

If you are using Using @capgo/capacitor-health to plan native plugin work, connect it with @capgo/capacitor-health for the implementation detail in @capgo/capacitor-health, Getting Started for the implementation detail in Getting Started, Capgo Plugin Directory for the product workflow in Capgo Plugin Directory, Capacitor Plugins by Capgo for the implementation detail in Capacitor Plugins by Capgo, and Adding or Updating Plugins for the implementation detail in Adding or Updating Plugins.

FAQ

Health plugin FAQ

How do I install the Health plugin in a Capacitor app?

Run "bun add @capgo/capacitor-health" (or "npm install @capgo/capacitor-health"), then run "bunx cap sync" so the iOS and Android projects pick up the native code. Import it from "@capgo/capacitor-health" in your app code.

Does @capgo/capacitor-health work with React, Vue and Angular?

Yes. Health is a Capacitor package, so it works with any web framework that runs inside Capacitor, including Ionic, React, Vue, Angular, Svelte and plain JavaScript.

Which Capacitor version does @capgo/capacitor-health support?

Capgo plugins follow Capacitor's major version: use the plugin major version that matches your Capacitor major version (for example plugin v8 with Capacitor 8). The compatibility table in the GitHub README lists the maintained versions.

Is @capgo/capacitor-health free and open source?

Yes. The source code is public on GitHub at https://github.com/Cap-go/capacitor-health/ and the package is free to install from npm. Bug reports and pull requests are welcome.

Can I update code that uses Health without an App Store review?

Installing or upgrading the plugin changes native code, so it needs a new store build. After that, JavaScript, HTML and CSS changes that call the plugin can ship instantly with Capgo live updates.

Ship Health changes without waiting for app review

Once the plugin is in your store build, Capgo live updates push your JavaScript, HTML and CSS changes to users in minutes.

Start with Capgo