가이드
Capacitor에서 Health 사용 방법
@capgo/capacitor-health 사용하기
Apple HealthKit 및 Health Connect 데이터와 연동하는 Capacitor 플러그인
설치
bun add @capgo/capacitor-health
bunx cap sync
bunx cap sync 플러그인의 네이티브 code를 네이티브 프로젝트에 복사합니다. 플러그인을 업그레이드할 때마다 다시 실행하세요.
가져오기
import { Health } from '@capgo/capacitor-health';
API 한눈에 보기
| 메서드 | 설명 |
|---|---|
isAvailable |
현재 플랫폼이 네이티브 health SDK를 지원하는지 여부를 반환합니다. |
requestAuthorization |
지정된 데이터 타입에 대한 읽기/쓰기 권한을 요청합니다. |
checkAuthorization |
사용자에게 프롬프트를 표시하지 않고 지정된 데이터 타입의 권한 상태를 확인합니다. |
readSamples |
지정된 시간 범위 내에서 해당 데이터 타입의 샘플을 읽어옵니다. |
saveSample |
네이티브 health 스토어에 단일 샘플을 기록합니다. |
openHealthConnectSettings |
Health Connect 설정 화면을 엽니다 (Android 전용). iOS에서는 동작하지 않습니다. |
showPrivacyPolicy |
Health Connect에 대한 앱 개인정보 처리방침을 표시합니다 (Android 전용). iOS에서는 동작하지 않습니다. |
queryWorkouts |
네이티브 헬스 스토어에서 운동 세션 데이터를 조회합니다. iOS (HealthKit) 및 Android (Health Connect)를 지원합니다. |
queryAggregated |
네이티브 헬스 스토어에서 집계된 건강 데이터를 조회합니다. 데이터를 시간 단위(시간, 일, 주, 월)로 묶고 합계, 평균, 최소, 최대 등의 연산을 수행합니다. 이는 넓은 날짜 범위에 대해 개별 샘플을 가져오는 것보다 훨씬 효율적입니다. |
예시
isAvailable()
현재 플랫폼이 네이티브 건강 SDK을(를) 지원하는지 여부를 반환합니다.
import { Health } from '@capgo/capacitor-health';
const result = await Health.isAvailable();
console.log(result);
requestAuthorization()
지정된 데이터 유형에 대한 읽기/쓰기 권한을 요청합니다.
import { Health } from '@capgo/capacitor-health';
const result = await Health.requestAuthorization({ read: ['steps'] });
console.log(result);
checkAuthorization()
사용자에게 prompt를 띄우지 않고 지정된 데이터 유형에 대한 권한 상태를 확인합니다.
import { Health } from '@capgo/capacitor-health';
const result = await Health.checkAuthorization({ read: ['steps'] });
console.log(result);
readSamples()
지정된 시간 범위 내에서 해당 데이터 유형의 샘플을 읽어옵니다.
import { Health } from '@capgo/capacitor-health';
const result = await Health.readSamples({ dataType: 'steps' });
console.log(result);
saveSample()
네이티브 헬스 스토어에 단일 샘플을 기록합니다.
import { Health } from '@capgo/capacitor-health';
await Health.saveSample({
dataType: 'steps',
value: 1,
});
openHealthConnectSettings()
Health Connect 설정 화면을 엽니다 (Android 전용). iOS에서는 아무 동작도 수행하지 않습니다.
import { Health } from '@capgo/capacitor-health';
await Health.openHealthConnectSettings();
위 테이블에는 9개의 핵심 메서드가 나열되어 있습니다. Listener 및 version helper, 그리고 각 메서드의 전체 contract는 다음 문서에서 확인할 수 있습니다. GitHub 리포지토리.
전체 레퍼런스
@capgo/capacitor-health 사용하기부터 이어서 보기
사용 중이라면 @capgo/capacitor-health 사용하기 네이티브 플러그인 작업을 계획하려면, 이를 다음 항목과 연결하세요: @capgo/capacitor-health @capgo/capacitor-health의 구현 세부 사항에 대해서는, 시작하기 Getting Started의 구현 상세 내용은 Capgo 플러그인 디렉토리 Capgo Plugin Directory의 제품 워크플로우에 맞춰, Capgo의 Capacitor 플러그인 Capgo의 Capacitor Plugins 구현 세부 사항 및 플러그인 추가 또는 업데이트 플러그인 추가 또는 업데이트의 구현 세부 사항은.