iOS Setup
Manual setup for bare React Native projects without Expo.
Prerequisites
- React Native 0.70+
- Xcode 14+
- iOS 13.0+ deployment target
Installation
npm install react-native-healthx
# or
yarn add react-native-healthx
Install pods:
cd ios && pod install
Enable HealthKit Capability
- Open your project in Xcode
- Select your project in the navigator
- Select your app target
- Go to Signing & Capabilities tab
- Click + Capability
- Search for and add HealthKit
After adding the capability, you should see "HealthKit" listed under Signing & Capabilities with a checkmark.
Configure Info.plist
Add the required usage descriptions to ios/YourApp/Info.plist:
<dict>
<!-- ... other entries ... -->
<key>NSHealthShareUsageDescription</key>
<string>We need access to your health data to provide sleep insights.</string>
<key>NSHealthUpdateUsageDescription</key>
<string>We need to save your health data.</string>
</dict>
Replace the placeholder text with descriptions that explain why your app needs access to health data. Apple reviews these messages during app review.
Verify Entitlements
The HealthKit entitlements should be automatically added. Verify in ios/YourApp/YourApp.entitlements:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.healthkit</key>
<true/>
<key>com.apple.developer.healthkit.access</key>
<array/>
</dict>
</plist>
Build and Run
npx react-native run-ios
Testing
HealthKit is not available in the iOS Simulator. You must test on a physical device.
To test on a device:
- Connect your iPhone
- Select your device in Xcode
- Build and run
You can add test data in the Health app on your device:
- Open the Health app
- Go to Browse → Sleep
- Tap "Add Data"
Platform Limitations
Sleep Data Write
iOS HealthKit does not allow third-party apps to write sleep analysis data. The writeSession() method will throw an error on iOS.
if (HealthX.supportsWrite()) {
await HealthX.sleep.writeSession({ ... });
} else {
console.log('Write not supported on this platform');
}
Sleep Stages
Detailed sleep stages (CORE, DEEP, REM, AWAKE) are only available on iOS 16 and later. On older versions, you'll only see IN_BED and ASLEEP stages.