README

This package allows access to health & fitness data exposed by Apple Healthkit. You can see the methods available here.
If you are looking for a more robust solution providing normalized data, insights and recommendations based on user's biometric data, data from multiple sources (Fitbit, Oura), or a hosted solution, please check out the Point SDK developed by our frens.
🚨 Expo: This package is not available in the Expo Go app. Learn how you can use it with custom dev clients.
- 1.
yarn add react-native-health
- 2.
pod install
Or, if you need to manually link it, run
react-native link react-native-health
- 3.Update the
ios/<Project Name>/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>
<!-- Below is only required if requesting clinical health data -->
<key>NSHealthClinicalHealthRecordsShareUsageDescription</key>
<string>Read and understand clinical health data.</string>
To add Healthkit support to your application's
Capabilities
- Open the
ios/
folder of your project in Xcode - Select the project name in the left sidebar
- In the main view select '+ Capability' and double click 'HealthKit'
To enable access to clinical data types, check the
Clinical Health Records
box.In order to start collecting or saving data to HealthKit, you need to request the user's permissions for the given data types. It can be done in the following way
import AppleHealthKit, {
HealthValue,
HealthKitPermissions,
} from 'react-native-health'
/* Permission options */
const permissions = {
permissions: {
read: [AppleHealthKit.Constants.Permissions.HeartRate],
write: [AppleHealthKit.Constants.Permissions.Steps],
},
} as HealthKitPermissions
AppleHealthKit.initHealthKit(permissions, (error: string) => {
/* Called after we receive a response from the system */
if (error) {
console.log('[ERROR] Cannot grant permissions!')
}
/* Can now read or write to HealthKit */
const options = {
startDate: new Date(2020, 1, 1).toISOString(),
}
AppleHealthKit.getHeartRateSamples(
options,
(callbackError: string, results: HealthValue[]) => {
/* Samples are now collected from HealthKit */
},
)
})
For background capabilities, Apple allows developers to setup long running observer queries for the health types needed.
To set that up in your app, in XCode open your
ios/AppDelegate.m
file and add the following statements:#import "AppDelegate.h"
...
/* Add the library import at the top of AppDelegate.m */
#import "RCTAppleHealthKit.h"
...
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self
launchOptions:launchOptions];
...
/* Add Background initializer for HealthKit */
[[RCTAppleHealthKit new] initializeBackgroundObservers:bridge];
...
return YES;
}
After that you can start listening for data updates using the React Native client. For more information, see background observers.
Vitals Methods
Workout Methods
Due to Apple's privacy model, if a user has previously denied a specific permission they will not be prompted again for that permission. The user will need to go into the Apple Health app and grant the permission to your app.
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 when initializing the library.
If extra read or write permissions are added to the options object, the app will request the user's permission when the library is initialized again.
- 1.Run
yarn add react-native-health
- 2.In XCode, in the project navigator, right-click
Libraries
➜Add Files to [your project's name]
- 3.Go to
node_modules
➜react-native-health
and addRCTAppleHealthkit.xcodeproj
- 4.In XCode, in the project navigator, select your project. Add
libRCTAppleHealthkit.a
to your project'sBuild Phases
➜Link Binary With Libraries
- 5.Click
RCTAppleHealthkit.xcodeproj
in the project navigator and go theBuild Settings
tab. Make sure 'All' is toggled on (instead of 'Basic'). In theSearch Paths
section, look forHeader Search Paths
and make sure it contains both$(SRCROOT)/../../react-native/React
and$(SRCROOT)/../../../React
- mark both asrecursive
. - 6.Enable Healthkit in your application's
Capabilities
- 7.Compile and run
We appreciate any requests and contributions to
react-native-health
. The issues tracker is used to keep a list of features and bugs to be worked on. Please see our contributing documentation for some tips on getting started.If your app needs an Android + Health Connect integration, your princess is in another castle. You can use the package React Native Health Connect maintained by one of the community's dev.
In case of questions or if you just want to congratz the author, you can reach out to him on our Discord Server.
This package is maintained with ❤️ by AE Studio. We will do our best to respond to requests and support for this package so please get in touch! If you require more extensive help or have other design, data science or development needs - we are a full service product development agency and can build pretty much anything so hit us up!
Last modified 14d ago