Package Exports
- react-native-health
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-native-health) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
React Native Health
A React Native package to interact with Apple HealthKit for iOS.
Getting Started
Automatic Installation
Install the react-native-health package from npm
yarn add react-native-healthIf you are using CocoaPods you can run the following
from the ios/ folder of your app
pod installOr, if you need to manually link it, run
react-native link react-native-healthUpdate the info.plist file in your project
<key>NSHealthShareUsageDescription</key>
<string>Read and understand health data.</string>
<key>NSHealthUpdateUsageDescription</key>
<string>Share workout data with other apps.</string>Manual Installation
- Run
yarn add react-native-health - In XCode, in the project navigator, right-click
Libraries➜Add Files to [your project's name] - Go to
node_modules➜react-native-healthand addRCTAppleHealthkit.xcodeproj - In XCode, in the project navigator, select your project. Add
libRCTAppleHealthkit.ato your project'sBuild Phases➜Link Binary With Libraries - Click
RCTAppleHealthkit.xcodeprojin the project navigator and go theBuild Settingstab. Make sure 'All' is toggled on (instead of 'Basic'). In theSearch Pathssection, look forHeader Search Pathsand make sure it contains both$(SRCROOT)/../../react-native/Reactand$(SRCROOT)/../../../React- mark both asrecursive. - Enable Healthkit in your application's
Capabilities
- Compile and run
Get Started
Initialize Healthkit. This will show the Healthkit permissions prompt for any read/write permissions set in the required options object.
Due to Apple's privacy model if an app user has previously denied a specific permission then they can not be prompted again for that same permission. The app user would have to go into the Apple Health app and grant the permission to your react-native app under sources tab.
For any data that is read from Healthkit the status/error is the same for both. This privacy restriction results in having no knowledge of whether the permission was denied (make sure it's added to the permissions options object), or the data for the specific request was nil (ex. no steps recorded today).
For any data written to Healthkit an authorization error can be caught. If an authorization error occurs you can prompt the user to set the specific permission or add the permission to the options object if not present.
If new read/write permissions are added to the options object then the app user will see the Healthkit permissions prompt with the new permissions to allow.
initHealthKit requires an options object with Healthkit permission settings
let options = {
permissions: {
read: ["Height", "Weight", "StepCount", "DateOfBirth", "BodyMassIndex", "ActiveEnergyBurned"],
write: ["Height", "Weight", "StepCount", "BodyMassIndex", "Biotin", "Caffeine", "Calcium", "Carbohydrates", "Chloride", "Cholesterol", "Copper", "EnergyConsumed", "FatMonounsaturated", "FatPolyunsaturated", "FatSaturated", "FatTotal", "Fiber", "Folate", "Iodine", "Iron", "Magnesium", "Manganese", "Molybdenum", "Niacin", "PantothenicAcid", "Phosphorus", "Potassium", "Protein", "Riboflavin", "Selenium", "Sodium", "Sugar", "Thiamin", "VitaminA", "VitaminB12", "VitaminB6", "VitaminC", "VitaminD", "VitaminE", "VitaminK", "Zinc", "Water"]
}
};import AppleHealthKit from 'react-native-health';
AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) => {
if (err) {
console.log("error initializing Healthkit: ", err);
return;
}
// Height Example
AppleHealthKit.getDateOfBirth(null, (err: Object, results: Object) => {
if (this._handleHealthkitError(err, 'getDateOfBirth')) {
return;
}
console.log(results)
});
});{
value: '1986-09-01T00:00:00.000-0400',
age: 29
}Documentation
- Installation
- Documentation
- Permissions
- Units
- Base Methods
- Realtime Methods
- Read Methods
- getActiveEnergyBurned
- getBasalEnergyBurned
- getBiologicalSex
- getBloodAlcoholContentSamples
- getBloodGlucoseSamples
- getBloodPressureSamples
- getBodyTemperatureSamples
- getDailyDistanceCyclingSamples
- getDailyDistanceWalkingRunningSamples
- getDailyFlightsClimbedSamples
- getDailyStepCountSamples
- getDateOfBirth
- getDistanceCycling
- getDistanceSwimming
- getDistanceWalkingRunning
- getFlightsClimbed
- getHeartRateSamples
- getHeartRateVariabilitySamples
- getRestingHeartRateSamples
- getVo2MaxSamples
- getHeightSamples
- getLatestBloodAlcoholContent
- getLatestBmi
- getLatestBodyFatPercentage
- getBodyFatPercentageSamples
- getLatestHeight
- getLatestLeanBodyMass
- getLeanBodyMassSamples
- getLatestWeight
- getRespiratoryRateSamples
- getSleepSamples
- getStepCount
- getWeightSamples
- getSamples
- getMindfulSession
- Write Methods
- References
Supported Apple Permissions
The available Healthkit permissions to use with initHealthKit
These permissions are exported as constants of the react-native-health module.
import AppleHealthKit from 'react-native-health';
// get the available permissions from AppleHealthKit.Constants object
const PERMS = AppleHealthKit.Constants.Permissions;
// setup healthkit read/write permissions using PERMS
const healthKitOptions = {
permissions: {
read: [
PERMS.StepCount,
PERMS.Height,
],
write: [
PERMS.StepCount
],
}
};Units
- bpm
- calorie
- celsius
- count
- day
- fahrenheit
- foot
- gram
- hour
- inch
- joule
- meter
- mgPerdL
- mile
- minute
- mmhg
- mmolPerL
- percent
- pound
- second
References
Acknowledgement
This package is a fork of rn-apple-healthkit
This package also inherits additional features from Nutrisense fork