Menu

contact us

Unleashing the Potential of React Native Healthkit: Strengthening Health and Fitness Apps

Get the inside scoop on the latest healthcare trends and receive sneak peeks at new updates, exclusive content, and helpful tips.

Contact Us






    Posted in Health Wearables

    Last Updated | April 1, 2024

    Unleashing the Potential of React Native Healthkit: Strengthening Health and Fitness Apps

    Fitness and health are changing due to wearable technology, which provides real-time data about our well-being. Wearables transform healthcare by changing how diseases are managed, prevented, and treated. These health monitoring devices enable users to make better decisions by providing rapid access to critical indicators like heart rate and activity levels. 

    React Native Healthkit

    Furthermore, wearables are revolutionizing healthcare delivery by allowing telemedicine and remote patient monitoring, guaranteeing everyone’s access to care. In this blog, we’ll discuss React Native HealthKit. To communicate with Apple HealthKit for iOS, we will use React Native Health, a react native package that allows access to health and fitness data exposed by Apple HealthKit. The methods are available here

    We will go through using the Apple HealthKit APIs and gaining access to Apple HealthKit in detail.

    Getting Started

    The “Expo Go” app is unable to utilise this package. Find out how to apply it for bespoke development clients.

    Installation

    First and foremost, we can start by installing the react-native-health in our React-Native project.

    Run the following command:

    You can use either npm or yarn to install the package.

      yarn add react-native-health

    or

      npm i react-native-health

    • If you are using CocoaPodsyou can run the following from the ios/ folder of your app.

      pod install

    • Or, if you need to link it manually, run

      react-native link react-native-health

    • 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

    • Launch Xcode and navigate to your project’s ios/ folder.
    • Choose the project name from the sidebar on the left.
    • Double click ‘HealthKit’ after selecting ‘+ Capability’ in the central pane.
    • Check the box next to Clinical Health Records to allow access to certain types of clinical data.

    Usage:

    Before you can begin data collection or storage in HealthKit, you must ask the user for permission to collect or save the specified data types. There are several ways to do this.

     import AppleHealthKit, {

        HealthKitPermissions,

      } from ‘react-native-health’

      /* Permission options */

      const permissions = {

        permissions: {

          read: [AppleHealthKit.Constants.Permissions.HeartRate],

          write: [AppleHealthKit.Constants.Permissions.Steps],

        },

      } as HealthKitPermissions

    Click here for additional permissions.

    Background Processing

    Apple permits developers to set up persistent observer queries for the required health kinds to have background capabilities.

    Open your ios/AppDelegate.m file in XCode and add the following statements to configure that in your app:

      #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;

      }

    Subsequently, you can use the React Native client to listen for data updates. See background observers for additional details.

    Initialize Apple HealthKit

      AppleHealthKit.initHealthKit(

        (options: HealthInputOptions),

        (err: string, results: boolean) => {

          if (err) {

            console.log(‘error initializing Healthkit: ‘, err)

            return

          }

          // Healthkit is initialized…

          //Now it is safe to read and write Healthkit data…

        },

      )

    Check for HealthKit availability.

      Import AppleHealthKit from ‘react-native-health’

      AppleHealthKit.isAvailable((err: Object, available: boolean) => {

        if (err) {

          console.log(‘error initializing Healthkit: ‘, err)

          return

        }

      })

    Example output:

      true

    Implementation

    implementation of react native healthkit

    We will now review various samples that may be obtained from the Apple HealthKit using the Apple HealthKit API’s. 

    • Weight
    • Height
    • BMI
    • Biological Sex
    • Energy Consumed
    • Protein
    • Insulin Delivery
    • Daily Step Count
    • Step Count
    • Calories
    • ActiveEnergyBurned
    • BasalEnergyBurned
    • DailyDistanceWalkingRunning
    • DailyDistanceSwimming
    • Sleep
    • Blood Pressure
    • Electrocardiogram
    • Heart Rate
    • Heart Rate Variability
    • Heartbeat Series
    • Oxygen Saturation
    • Resting Heart Rate
    • Vo2Max
    • Respiratory Rate
    • Walking Heart Rate

    Weight:

    Code Sample

      let options = {

        unit: ‘pound’, // optional; default ‘pound’

       startDate: new Date(2024, 0, 0).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

        ascending: false, // optional; default false

        limit: 10, // optional; default no limit

      }

      AppleHealthKit.getWeightSamples(

        options,

        (err: Object, results: Array<HealthValue>) => {

          if (err) {

            return

          }

          console.log(results)

        },

      )

    Output

      [

        {

        // The universally unique identifier (UUID) for this HealthKit object.

          “id”: “3d366e60-4f7c-4f72-b0ce-479ea19279b8”,  

          “value”: 160,

          “startDate”: “2024-07-09T00:00:00.000-0400”,

          “endDate”: “2024-07-10T00:00:00.000-0400”,

          “metadata”: {

           “HKWasUserEntered”: false

          }

        },

        {

          “id”: “cb7a2de6-f8d2-48cc-8cca-3d9f58a3601a”,

          “value”: 161,

          “startDate”: “2024-07-08T00:00:00.000-0400”,

          “endDate”: “2024-07-09T00:00:00.000-0400”,

          “metadata”: {

           “HKWasUserEntered”: false

          }

        },

        {

          “id”: “4dddd4da-2adf-4d1c-a400-10790ffe2c0d”,

          “value”: 165,

          “startDate”: “2024-07-07T00:00:00.000-0400”,

          “endDate”: “2024-07-08T00:00:00.000-0400”,

          “metadata”: {

            “HKWasUserEntered”: false

          }

        }

      ]

    Healthcare app development

    Height

    Code Sample

      let options = {

        unit: ‘inch’, // optional; default ‘inch’

        startDate: new Date(2024, 0, 0).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

        ascending: false, // optional; default false

        limit: 10, // optional; default no limit

      }

      AppleHealthKit.getHeightSamples(

        options,

        (err: Object, results: Array<HealthValue>) => {

          if (err) {

            return

          }

          console.log(results)

        },

      )

    Output

      [

        {

        // The universally unique identifier (UUID) for this HealthKit object.

          “id”: “3d366e60-4f7c-4f72-b0ce-479ea19279b8”, 

          “value”: 74.02,

          “startDate”: “2024-06-29T17:55:00.000-0400”,

          “endDate”: “2024-06-29T17:55:00.000-0400”,

          “metadata”: {

           “HKWasUserEntered”: true,

          }

      },

      {

        “id”: “19a9910d-230a-437f-a830-353f6e61f676”,

        “value”: 74,

        “startDate”: “2024-03-12T13:22:00.000-0400”,

        “endDate”: “2024-03-12T13:22:00.000-0400”,

        “metadata”: {

            “HKWasUserEntered”: true,

          }

        }

      ]

    BMI

    Code Sample

      let options = {

        startDate: new Date(2024, 0, 0).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

        ascending: false, // optional; default false

        limit: 10, // optional; default no limit

      }

      AppleHealthKit.getBmiSamples(

        options,

        (err: Object, results: Array<HealthValue>) => {

          if (err) {

            return

          }

          console.log(results)

        },

      )

    Output

      [

        {

          “endDate”: “2024-10-10T09:19:00.000+0000”, 

        // The universally unique identifier (UUID) for this HealthKit object.

          “id”: “73A653BA-4715-47BD-98FE-E9AA91DB33CA”, 

          “sourceId”: “com.apple.Health”, 

          “sourceName”: “Health”, 

          “startDate”: “2024-10-19T09:19:00.000+0000”, 

          “value”: 18.5

        },

        {

          “endDate”: “2024-08-23T08:50:00.000+0000”,

          “id”: “B3D8B5BE-216C-4C10-A96E-3B2CF8EB646E”,

          “sourceId”: “com.apple.Health”,

          “sourceName”: “Health”,

          “startDate”: “2024-08-23T08:50:00.000+0000”,

          “value”: 18.83

        }

      ]

    Biological Sex

    Code Sample

      AppleHealthKit.getBiologicalSex(null, (err: Object, results: Object) =>     

      {

        if (err) {

          return

        }

        console.log(results)

      })

    Output

      {

        “value”: “female”

      }

    Energy Consumed

    Code Sample

      let options = {

        startDate: new Date(2024, 0, 0).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

      }

      AppleHealthKit.getEnergyConsumedSamples(

        (options: HealthInputOptions),

        (err: Object, results: HealthValue) => {

          if (err) {

            return

          }

          console.log(results)

        },

      )

    Output

      [

        {

          “endDate”: “2024-04-01T22:00:00.000+0300”, 

          “startDate”: “2024-04-01T22:00:00.000+0300”, 

          “value”: 204.5,

          “metadata”: {

            “HKWasUserEntered”: true,

          }

        }

      ]

    Protein

    Code Sample

      let options = {

        startDate: new Date(2024, 0, 0).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

      }

      AppleHealthKit.getProteinSamples(

        (options: HealthInputOptions),

        (err: Object, results: HealthValue) => {

          if (err) {

            return

          }

          console.log(results)

        },

      )

    Output

      [

        {

          “id”: “5013eca7-4aee-45af-83c1-dbe3696b2e51”, 

      // The universally unique identifier (UUID) for this HealthKit object.

          “endDate”: “2024-04-01T22:00:00.000+0300”, 

          “startDate”: “2024-04-01T22:00:00.000+0300”, 

          “value”: 39,

          “metadata”: {

            “HKWasUserEntered”: true,

          }

        }

      ]

    Insulin Delivery

    Code Sample

      let options = {

        startDate: new Date(2024, 0, 0).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

        ascending: false, // optional; default false

        limit: 10, // optional; default no limit

      }

      AppleHealthKit.getInsulinDeliverySamples(

          options,

          (callbackError: string, results: HealthValue[]) => {

              console.log(results)

          },

      );

    Output

      [

        {

          “id”: “8DE6A905-02B7-41D2-BB6E-67D1DD82DD6F”, // The universally unique identifier (UUID) for this HealthKit object.

          “endDate”: “2024-03-22T16:19:00.000-0300”,

          “sourceId”: “com.apple.Health”,

          “sourceName”: “Health”,

         “startDate”: “2024-03-22T16:19:00.000-0300”,

          “value”: 5,

          “metadata”: {

            “HKWasUserEntered”: true,

            “HKInsulinDeliveryReason”: 2, // Basal = 1, Bolus = 2

          }

        }

      ]

     

    Daily Step Count

    Code Sample

      let options = {

          startDate: (new Date(2024,1,1)).toISOString() // required

          endDate:   (new Date()).toISOString() // optional; default now

      };

     

      AppleHealthKit.getDailyStepCountSamples(

        (options: HealthInputOptions),

        (err: Object, results: Array<Object>) => {

          if (err) {

            return

          }

          console.log(results)

        },

      )

    Output

     [

        {

          “endDate”: “2024-03-22T17:00:00.000-0300”,

          “startDate”: “2024-03-22T16:00:00.000-0300”,

          “value”: 3978

        }

      ]

     

    Step Count

    Code Sample

      let options = {

          date: new Date().toISOString(), // optional; default now

          includeManuallyAdded: false. // optional: default true

      };

     

      AppleHealthKit.getStepCount(

        (options: HealthInputOptions),

        (err: Object, results: HealthValue) => {

          if (err) {

            return

          }

          console.log(results)

        },

      )

    Output

      {

        “value”: 213

      }

     

    Active Energy Burned / Active Kilocalories

    Code Sample

      let options = {

        startDate: new Date(2024, 0, 0).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

        ascending: true, // optional

        includeManuallyAdded: true, // optional

      }

     

     

      AppleHealthKit.getActiveEnergyBurned(

        (options: HealthInputOptions),

        (err: Object, results: HealthValue) => {

          if (err) {

            return

          }

          console.log(results)

        },

      )

    Output

      [

        {

          “endDate”: “2024-03-22T16:00:00.000-0300”,

          “startDate”: “2024-03-22T15:00:00.000-0300”,

          “value”: 123

        }

      ]

     

    Basal Energy Burned / Resting Energy

    Code Sample

      let options = {

        startDate: new Date(2018, 10, 1).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

        ascending: true, // optional

        includeManuallyAdded: true, // optional

      }

     

      AppleHealthKit.getBasalEnergyBurned(

        (options: HealthInputOptions),

        (err: Object, results: HealthValue) => {

          if (err) {

            return

          }

          console.log(results)

        },

      )

    Output

      

      [

        {

          “endDate”: “2024-03-22T17:00:00.000-0300”,

          “startDate”: “2024-03-22T16:00:00.000-0300”,

          “value”: 42

        }  

      ]

     

    Sleep

    Code Sample

      let options = {

        startDate: new Date(2024, 0, 0).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

        limit: 10, // optional; default no limit

        ascending: true, // optional; default false

      }

     

      AppleHealthKit.getSleepSamples(options, (err: Object, results:     Array<HealthValue>) => {

        if (err) {

          return;

        }

        console.log(results).

       });

    Output

      

      [

        {

          “id”: “3d366e60-4f7c-4f72-b0ce-479ea19279b8”, // The universally   unique identifier (UUID) for this HealthKit object.

          “endDate”: “2024-03-22T16:34:00.000-0300”,

          “sourceId”: “com.apple.Health”,

          “sourceName”: “Health”,

          “startDate”: “2024-03-22T15:34:00.000-0300”,

          “value”: “INBED”

        }

      ]

     

    Blood Pressure

    Code Sample

      let options = {

        unit: ‘mmhg’, // optional; default ‘mmhg’

        startDate: new Date(2024, 0, 0).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

        ascending: false, // optional; default false

        limit: 10, // optional; default no limit

      }

     

      AppleHealthKit.getBloodPressureSamples(

        options,

        (err: Object, results: Array<HealthValue>) => {

          if (err) {

            return

          }

          console.log(results)

        },

      )

    Output

      [

        {

          “bloodPressureSystolicValue”: 120,

          “bloodPressureDiastolicValue”: 81,

          “startDate”: “2024-06-29T17:55:00.000-0400”,

          “endDate”: “2024-06-29T17:55:00.000-0400”

        },

        {

          “bloodPressureSystolicValue”: 119,

          “bloodPressureDiastolicValue”: 77,

          “startDate”: “2024-03-12T13:22:00.000-0400”,

          “endDate”: “2024-03-12T13:22:00.000-0400”

        }

      ]

     

    Electrocardiogram

    Code Sample

     let options = {

        startDate: new Date(2024, 0, 0).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

        ascending: false, // optional; default false

        limit: 1, // optional; default no limit

      }

     

      AppleHealthKit.getElectrocardiogramSamples(

        (options: HealthInputOptions),

        (err: Object, results: ElectrocardiogramSampleValue[]) => {

          if (err) {

            return

          }

          console.log(results)

        },

      )

    Output

     

     [

        {

          “id”: “5AF5F9E0-F27E-4BD7-8DBD-B7E00B9C68CF”,

          “sourceName”: “ECG”,

          “sourceId”: “com.apple.NanoHeartRhythm”,

          “startDate”: “2024-06-16T19:10:52.498-0400”,

          “endDate”: “2024-06-16T19:11:22.499-0400”,

          “classification”: “SinusRhythm”, 

         // see ElectrocardiogramClassification enum

          “averageHeartRate”: 62,

          “samplingFrequency”: 512.6171875,

          “device”: “Watch4,1”,

          “algorithmVersion”: 2,

          “voltageMeasurements”: [

            // [timeSinceSampleStart (s), voltage (V)]

            [0, -0.000007642375469207763],

            [0.0019507734511925627, -0.000005802469730377197],

            [0.0039015469023851255, -0.000003958822011947631],

            [0.005852320353577688, -0.0000021150546073913572],

            [0.007803093804770251, -2.747770547866821e-7],

            // …

            [29.991191038634458, -0.00003649459075927734],

            [29.99314181208565, -0.000035267024993896485],

            [29.995092585536845, -0.000033975482940673826],

            [29.997043358988037, -0.00003262416076660156],

            [29.99899413243923, -0.000031217338562011714]

          ]

        }

      ]

     

    Heart Rate

    Code Sample

      let options = {

        unit: ‘bpm’, // optional; default ‘bpm’

        startDate: new Date(2024, 0, 0).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

        ascending: false, // optional; default false

        limit: 10, // optional; default no limit

      }

     

      AppleHealthKit.getHeartRateSamples(

        options,

        (err: Object, results: Array<HealthValue>) => {

          if (err) {

            return

          }

          console.log(results)

        },

      )

    Output

      [

        {

          “id”: “5013eca7-4aee-45af-83c1-dbe3696b2e51”, 

         // The universally unique identifier (UUID) for this HealthKit object.

          “value”: 74.02,

          “startDate”: “2024-06-29T17:55:00.000-0400”,

          “endDate”: “2024-06-29T17:55:00.000-0400”,

          “metadata”: {

            “HKWasUserEntered”: false

          }

        },

        {

          “id”: “4ea9e479-86e2-4e82-8030-86a9a9b8e569”,

          “value”: 74,

          “startDate”: “2024-03-12T13:22:00.000-0400”,

          “endDate”: “2024-03-12T13:22:00.000-0400”,

          “metadata”: {

            “HKWasUserEntered”: false

          }

        }

      ]

     

    Heart Rate Variability

    Code Sample

      let options = {

        unit: ‘second’, // optional; default ‘second’

        startDate: new Date(2024, 0, 0).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

        ascending: false, // optional; default false

        limit: 10, // optional; default no limit

      }

     

      

      AppleHealthKit.getHeartRateVariabilitySamples(

        options,

        (err: Object, results: Array<HealthValue>) => {

          if (err) {

            return

          }

          console.log(results)

        },

      )

    Output

      

     [

        {

          “id”: “5013eca7-4aee-45af-83c1-dbe3696b2e51”, 

       // The universally unique identifier (UUID) for this HealthKit object.

          “value”: 0.4223,

          “startDate”: “2024-03-12T13:22:00.000-0400”,

          “endDate”: “2024-03-12T13:22:00.000-0400”,

          “metadata”: {

            “HKWasUserEntered”: false

          }

        }

      ]

     

    Heartbeat Series

    Code Sample

      let options = {

        startDate: new Date(2024, 0, 0).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

        ascending: false, // optional; default false

        limit: 10, // optional; default no limit

      }

     

      AppleHealthKit.getHeartbeatSeriesSamples(

        options,

        (err: Object, results: HeartbeatSeriesSampleValue[]) => {

          if (err) {

            return

          }

          console.log(results)

        },

      )

    Output

      [

        {

          “id”: “9728168D-CFD4-4946-BF94-2789ECD39A72”,

          “sourceName”: “Apple Watch”,

          “startDate”: “2024-07-10T08:55:31.307-0400”,

          “endDate”: “2024-07-10T08:56:34.731-0400”,

          “sourceId”: “com.apple.health”,

          “heartbeatSeries”: [

            {

              “timeSinceSeriesStart”: 0.97265625,

              “precededByGap”: false

            },

            {

              “timeSinceSeriesStart”: 1.55859375,

              “precededByGap”: false

            },

            {

              “timeSinceSeriesStart”: 2.16015625,

              “precededByGap”: false

            },

          ]

        }

      ]

     

    Oxygen Saturation

    Code Sample

      let options = {

        startDate: new Date(2024, 1, 1).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

        ascending: false, // optional; default false

        limit: 10, // optional; default no limit

      }

     

      AppleHealthKit.getOxygenSaturationSamples(

        options,

        (callbackError: Object, results: Array<HealthValue>) => {

          if (callbackError) {

            return

          }

          console.log(results)

        },

      )

    Output

     

     [

        {

          “id”: “5013eca7-4aee-45af-83c1-dbe3696b2e51”, // The universally unique identifier (UUID) for this HealthKit object.

          “endDate”: “2024-03-04T10:56:00.000-0500”,

          “sourceId”: “com.apple.Health”,

          “sourceName”: “Health”,

          “startDate”: “2024-03-04T10:56:00.000-0500”,

          “value”: 0.98,

          “metadata”: {

            “HKWasUserEntered”: false

          }

        },

        {

          “id”: “86ff59e7-f393-4f32-95fb-b0bf7027374d”,

          “endDate”: “2024-03-04T09:55:00.000-0500”,

          “sourceId”: “com.apple.Health”,

          “sourceName”: “Health”,

          “startDate”: “2024-03-04T09:55:00.000-0500”,

          “value”: 0.97,

          “metadata”: {

            “HKWasUserEntered”: false

          }

        },

      ]

     

    <<<CTA>>>

     

    Resting Heart Rate

    Code Sample

      let options = {

        unit: ‘bpm’, // optional; default ‘bpm’

        startDate: new Date(2024, 0, 0).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

        ascending: false, // optional; default false

        limit: 10, // optional; default no limit

      }

      

      AppleHealthKit.getRestingHeartRateSamples(

        options,

        (err: Object, results: Array<HealthValue>) => {

          if (err) {

            return

          }

          console.log(results)

        },

      )

    Output

      

      [

        {

          “id”: “5013eca7-4aee-45af-83c1-dbe3696b2e51”, // The universally unique identifier (UUID) for this HealthKit object.

          “value”: 74,

          “startDate”: “2024-03-12T13:22:00.000-0400”,

          “endDate”: “2024-03-12T13:22:00.000-0400”,

        “metadata”: {

            “HKWasUserEntered”: false

          }

        }

      ]

     

    Vo2Max

    Code Sample

      let options = {

        unit: ‘bpm’, // optional; default ‘ml/(kg * min)’

        startDate: new Date(2024, 0, 0).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

        ascending: false, // optional; default false

        limit: 10, // optional; default no limit

      }

      

      AppleHealthKit.getVo2MaxSamples(

        options,

        (err: Object, results: Array<HealthValue>) => {

          if (err) {

            return

          }

          console.log(results)

        },

      )

    Output

      

      [

        {

          “id”: “5013eca7-4aee-45af-83c1-dbe3696b2e51”, // The universally unique identifier (UUID) for this HealthKit object.

          “endDate”: “2024-03-22T16:35:00.000-0300”,

          “sourceId”: “com.apple.Health”,

          “sourceName”: “Health”,

          “startDate”: “2024-03-22T16:35:00.000-0300”,

          “value”: 2,

          “metadata”: {

            “HKWasUserEntered”: false

          }

        }

      ]

     

    Respiratory Rate

    Code Sample

      let options = {

        unit: ‘bpm’, // optional; default ‘bpm’

        startDate: new Date(2024, 0, 0).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

        ascending: false, // optional; default false

        limit: 10, // optional; default no limit

      }

      AppleHealthKit.getRespiratoryRateSamples(

        options,

        (err: Object, results: Array<HealthValue>) => {

          if (err) {

            return

          }

          console.log(results)

        },

      )

    Output

      

      [

        {

          “id”: “5013eca7-4aee-45af-83c1-dbe3696b2e51”, // The universally unique identifier (UUID) for this HealthKit object.

          “endDate”: “2024-03-22T16:32:00.000-0300”,

          “sourceId”: “com.apple.Health”,

          “sourceName”: “Health”,

          “startDate”: “2024-03-22T16:32:00.000-0300”,

          “value”: 45,

          “metadata”: {

            “HKWasUserEntered”: false

          }

        }

      ]

    Walking Heart Rate

    Code Sample

      let options = {

        unit: ‘bpm’, // optional; default ‘bpm’

        startDate: new Date(2024, 0, 0).toISOString(), // required

        endDate: new Date().toISOString(), // optional; default now

        ascending: false, // optional; default false

        limit: 10, // optional; default no limit

      }

      AppleHealthKit.getWalkingHeartRateAverage(

        options,

        (err: Object, results: HealthValue[]) => {

          if (err) {

            return;

          }

          console.log(results);

        },

      )

    Output

      [

        {

          “value”: 77,

          “sourceId”: “com.apple.health”,

          “id”: “6AFB1A69-0165-4495-9B9A-7C594B63D88C”,

          “sourceName”: “Source”,

          “startDate”: “2024-07-05T12:53:58.870-0400”,

          “endDate”: “2024-07-05T15:14:23.413-0400”,

          “metadata”: {

           “HKWasUserEntered”: false

          }

        },

        {

          “value”: 73,

          “sourceId”: “com.apple.health”,

          “id”: “A13D758C-DCD4-44FA-87A9-7DD63DED31F6”,

          “sourceName”: “Source”,

          “startDate”: “2024-07-04T00:00:25.881-0400”,

          “endDate”: “2024-07-04T11:39:15.130-0400”,

          “metadata”: {

            “HKWasUserEntered”: false

          }

        }

      ]

    Conclusion

    To sum up, the React Native Health library provides developers with an extensive toolkit to design all-encompassing health and fitness applications. Developers may create scalable, user-friendly solutions, enabling people to track fitness objectives, keep an eye on their health, and make educated lifestyle decisions by utilizing the benefits of React Native with wearable technology. 

    The React Native Health library is leading the way in innovation as technology develops, advancing digital health and completely changing how we think about personal wellness. It is important that we accept wearable technology’s promise to unlock a healthy future right now! Find out more about wearable devices for health monitoring and the future of wearable technology in healthcare

    Detailed Example

    For a more detailed example, check out the example from the library here:

    react-native-health 

    References

    Apple Healthkit Documentation

    FAQs

    How Do I Enable HealthKit on My Watch? / How Do I Activate Health on Apple Watch?

    Both questions have the same answer. If you have an iPhone with the HealthKit app, your Apple watch will sync all HealthKit data to it. All you need is an Apple watch and an iPhone with HealthKit enabled.

    Is Healthkit the Same as Apple Health?

    Yes, the HealthKit framework is built into Apple Watches and iPhones. This allows applications to access your health data consensually. 

    How to Enable HealthKit on Your App?

    While enabling HealthKit happens on the user’s device, your React Native app can request permission to access specific health data types. Here are some popular libraries to help you integrate HealthKit React Native:

    How to Enable HealthKit on an iPhone?

    There’s no single switch to enable HealthKit on an iPhone. It’s automatically enabled when you use the Health app. Granting permission to access HealthKit data happens within individual apps that request it.

    Is Setting up HealthKit on Independent Apple Watch app possible?

    Unfortunately, you cannot integrate HealthKit directly into a standalone Apple Watch app. HealthKit functionality is currently limited to apps running on an iPhone that can communicate with a paired Apple Watch.

     

    About the Author

    Ahmed Faraz Qaimkhani

    Ahmed Faraz Qaimkhani

    With over 5 years of experience in software development, I am a skilled full-stack developer who specialises in both web and mobile application development. My expertise is in designing strong, scalable, and user-friendly applications using the MEAN/MERN stack (MongoDB, Express.js, Angular/React.js, Node.js) and mobile technologies(React Native and Ionic).