Getting Started
이 콘텐츠는 아직 귀하의 언어로 제공되지 않습니다.
-
Install the plugin
Terminal window npm i @capgo/capacitor-healthTerminal window pnpm add @capgo/capacitor-healthTerminal window yarn add @capgo/capacitor-healthTerminal window bun add @capgo/capacitor-health -
Sync native projects
Terminal window npx cap syncTerminal window pnpm cap syncTerminal window yarn cap syncTerminal window bunx cap sync
iOS configuration
- Open
ios/App/App.xcworkspacein Xcode and enable the HealthKit capability. - Provide usage descriptions in
Info.plist:
<key>NSHealthShareUsageDescription</key><string>This app reads your health metrics to personalize your experience.</string><key>NSHealthUpdateUsageDescription</key><string>This app writes health data that you explicitly record.</string>Android configuration
Health data is powered by Health Connect. Make sure:
minSdkVersionis 26 or higher (Capacitor 5 already satisfies this).- Users have Health Connect installed (Android 14+ bundles it; earlier versions require a Play Store download).
- You guide users through the runtime permission UI when prompting for access.
Check availability and request access
import { Health } from '@capgo/capacitor-health';
const { available, reason } = await Health.isAvailable();if (!available) { console.warn('Health APIs unavailable:', reason); return;}
await Health.requestAuthorization({ read: ['steps', 'heartRate', 'weight'], write: ['weight'],});Read samples
const { samples } = await Health.readSamples({ dataType: 'steps', startDate: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(), endDate: new Date().toISOString(), limit: 200,});
samples.forEach((sample) => { console.log(sample.value, sample.startDate, sample.endDate);});Write samples
await Health.saveSample({ dataType: 'weight', value: 74.6, startDate: new Date().toISOString(),});Authorization management
- Use
checkAuthorization()to verify current read/write scopes and adjust your UI. - Handle denials gracefully by explaining why the data enhances the experience and offering a retry.
- Always respect the user’s privacy and only request the minimum scopes your feature requires.