A unified React Native interface for accessing health data from both Android Health Connect and iOS HealthKit.
- 🔄 Unified API - Single interface for both platforms
- 📊 Comprehensive Data Types - Steps, heart rate, sleep, workouts, nutrition, and more
- 🔐 Permission Management - Easy permission requests and status checks
- 📝 Read & Write - Full support for reading and writing health data
- 🔔 Real-time Updates - Subscribe to health data changes
- 📱 Turbo Modules - Built with React Native's new architecture
- React Native >= 0.70
- iOS 13.0+
- Android API 28+ (Android 9+)
- Android 14+: Health Connect is built into the framework (no setup needed)
- Android 9-13: Health Connect app must be installed from Play Store
yarn add @mbdayo/react-native-health-kits
# or
pnpm add @mbdayo/react-native-health-kits-
Enable HealthKit capability in Xcode:
- Open your project in Xcode
- Select your target → Signing & Capabilities
- Click "+ Capability" and add "HealthKit"
-
Add required Info.plist entries:
<key>NSHealthShareUsageDescription</key>
<string>We need access to your health data to display your fitness information.</string>
<key>NSHealthUpdateUsageDescription</key>
<string>We need access to update your health data.</string>- Install pods:
cd ios && pod install- Add Health Connect permissions to your
AndroidManifest.xml:
<!-- Inside <manifest> tag -->
<uses-permission android:name="android.permission.health.READ_STEPS" />
<uses-permission android:name="android.permission.health.WRITE_STEPS" />
<uses-permission android:name="android.permission.health.READ_HEART_RATE" />
<uses-permission android:name="android.permission.health.WRITE_HEART_RATE" />
<!-- Add other permissions as needed -->
<!-- Inside <application> tag -->
<activity
android:name="androidx.health.connect.client.permission.HealthPermissionsRequestActivity"
android:exported="true">
<intent-filter>
<action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
</intent-filter>
</activity>- Ensure Health Connect is installed on the device. The library will return
falsefromisAvailable()if Health Connect is not installed.
import HealthKits from '@mbdayo/react-native-health-kits';
// Check availability
const available = await HealthKits.isAvailable();
// Request permissions
const granted = await HealthKits.requestPermissions([
{ type: 'steps', access: 'read' },
{ type: 'heartRate', access: 'read' },
{ type: 'weight', access: 'write' },
]);
// Read steps data
const steps = await HealthKits.readData({
type: 'steps',
startDate: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000),
endDate: new Date(),
});
// Write weight data
await HealthKits.writeData({
type: 'weight',
value: 70.5,
unit: 'kg',
date: new Date(),
});// Subscribe to step updates
const subscription = HealthKits.subscribeToUpdates('steps', (data) => {
console.log('New steps data:', data);
});
// Unsubscribe when done
subscription.remove();// Get daily step totals for the last month
const dailySteps = await HealthKits.readData({
type: 'steps',
startDate: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000),
endDate: new Date(),
aggregate: true,
aggregateInterval: 'day',
});const sleepData = await HealthKits.readData({
type: 'sleep',
startDate: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000),
endDate: new Date(),
});
sleepData.forEach((session) => {
if (session.type === 'sleep') {
console.log(`Sleep duration: ${session.duration} minutes`);
console.log('Sleep stages:', session.stages);
}
});await HealthKits.writeData({
type: 'workout',
workoutType: 'running',
date: new Date(Date.now() - 60 * 60 * 1000), // 1 hour ago
endDate: new Date(),
totalEnergyBurned: 500, // kcal
totalDistance: 5000, // meters
});Check if health data services are available on the device.
Request permissions for specified health data types.
interface HealthPermission {
type: HealthDataType;
access: 'read' | 'write';
}Get the current authorization status for a specific data type.
Returns: 'authorized' | 'denied' | 'notDetermined' | 'unavailable'
Read health data based on provided options.
interface ReadOptions {
type: HealthDataType;
startDate: Date | string;
endDate: Date | string;
limit?: number;
aggregate?: boolean;
aggregateInterval?: 'hour' | 'day' | 'week' | 'month';
}Write health data.
Subscribe to real-time updates for a specific health data type.
Open Health Connect settings on Android. No-op on iOS.
| Data Type | iOS HealthKit | Android Health Connect |
|---|---|---|
steps |
✅ | ✅ |
distance |
✅ | ✅ |
activeCalories |
✅ | ✅ |
totalCalories |
✅ | ✅ |
floorsClimbed |
✅ | ✅ |
heartRate |
✅ | ✅ |
restingHeartRate |
✅ | ✅ |
heartRateVariability |
✅ | ✅ |
bloodPressureSystolic |
✅ | ✅ |
bloodPressureDiastolic |
✅ | ✅ |
bloodGlucose |
✅ | ✅ |
oxygenSaturation |
✅ | ✅ |
bodyTemperature |
✅ | ✅ |
respiratoryRate |
✅ | ✅ |
weight |
✅ | ✅ |
height |
✅ | ✅ |
bodyFatPercentage |
✅ | ✅ |
bmi |
✅ | |
leanBodyMass |
✅ | ✅ |
sleep |
✅ | ✅ |
workout |
✅ | ✅ |
hydration |
✅ | ✅ |
nutrition |
✅ | ✅ |
The following workout types are supported on both platforms:
walking,running,cycling,swimming,hikingyoga,strengthTraining,dance,elliptical,rowingstairClimbing,highIntensityIntervalTraining,jumpRope,pilatessoccer,basketball,tennis,badminton,martialArtsgolf,baseball,softball,volleyball,tableTennisskating,crossCountrySkiing,downhillSkiing,snowboardingsurfing,waterPolo,other
The library provides typed errors for common failure cases:
import { HealthKitError, HealthKitErrorCode } from '@mbdayo/react-native-health-kits';
try {
await HealthKits.readData({ ... });
} catch (error) {
if (error instanceof HealthKitError) {
switch (error.code) {
case HealthKitErrorCode.NOT_AVAILABLE:
console.log('Health data not available');
break;
case HealthKitErrorCode.PERMISSION_DENIED:
console.log('Permission denied');
break;
case HealthKitErrorCode.HEALTH_CONNECT_NOT_INSTALLED:
console.log('Health Connect not installed');
break;
}
}
}- HealthKit not available: HealthKit is only available on physical devices, not simulators.
- Permission not showing: Ensure you've added the required
Info.plistentries. - Background updates not working: Enable "Background Delivery" in HealthKit capabilities.
- Health Connect not available: On Android 9-13, ensure the Health Connect app is installed from Google Play Store. On Android 14+, it's built into the system.
- Permissions not granted: Users must manually grant permissions in Health Connect settings.
- Data not syncing: Some devices require the Health Connect app to be opened at least once.
- HealthKit requires a physical device for testing (not available in simulator)
- Some data types require special entitlements
- HealthKit doesn't reveal if read permission was denied for privacy reasons
- Android 14+: Health Connect is part of the Android Framework (no installation needed)
- Android 9-13: Health Connect is available via Play Store app
- Permissions are managed through the Health Connect settings
- Background data access requires additional setup
MIT
Contributions are welcome! Please read our contributing guidelines before submitting a pull request.