First, you need to add the necessary dependencies using yarn
or npm
:
yarn:
yarn add react-native-health
yarn add react-native-health-connect
yarn add react-native-health-link
npm:
npm install react-native-health
npm install react-native-health-connect
npm install react-native-health-link
Set up react-native-health following this instructions:
- Install pods:
cd ios && pod install
- 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.
More information on react-native-health's official GitHub page.
Make sure you have React Native version 0.71 or higher with the latest patch installed to use v2 of React Native Health Connect.
- Health Connect needs to be installed on the user's device. Starting from Android 14 (Upside Down Cake), Health Connect is part of the Android Framework. Read more here.
- Health Connect API requires minSdkVersion=26 (Android Oreo / 8.0).
- If you are planning to release your app on Google Play, you will need to submit a declaration form. Approval can take up to 7 days. Approval does not grant you immediate access to Health Connect. A whitelist must propagate to the Health Connect servers, which take an additional 5-7 business days. The whitelist is updated every Monday according to Google Fit AHP support.
package com.healthconnectexample
+ import android.os.Bundle
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
import com.facebook.react.defaults.DefaultReactActivityDelegate
+ import dev.matinzd.healthconnect.permissions.HealthConnectPermissionDelegate
class MainActivity : ReactActivity() {
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
override fun getMainComponentName(): String = "HealthConnectExample"
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ // In order to handle permission contract results, we need to set the permission delegate.
+ HealthConnectPermissionDelegate.setPermissionDelegate(this)
+ }
/**
* Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
* which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
*/
override fun createReactActivityDelegate(): ReactActivityDelegate =
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
}
You also need to setup permissions in your AndroidManifest.xml
file. For more information, check here.
More information on react-native-health-connects's official GitHub page.