Email Us

Health Kit

Use the Point Health Kit to collect and upload health samples to the Point Database.

Overview

Point Health Kit abstracts the main functionalities from Apple's Health kit in order to collect and upload health samples in an optimized and easy-to-implement way.

All methods are optimized for performance and low battery draining, the SDK has several internal optimizations including a small sqlite database to control and avoid uploading duplicated samples, reducing the network requests and data usage.

⚠️ All health kit methods require previous user authorization on the data types. Check the Permissions session.

Setup

Calling setupHealthkitIntegration(queryTypes:) will instantiate HealthKitManager within the SDK and it will be available for you to use. As this is the only way to create an instance of HealthKitManager, we suggest calling it as soon as possible, just after setup(clientId:clientSecret:fitbitClientId:environment:).

When setting up, you will need to send an Array of QueryType. These are the types of Health data you wish to collect when using the SDK. Assume that all the following features of this article will only work for the types you define in this step.

import { AppRegistry } from 'react-native'
import PointSdkRn, { QueryType } from 'react-native-point-sdk'

AppRegistry.registerComponent(appName, () => {
  PointSdkRn.setup('clientID', 'clientSecret', 'development', true, () =>
    console.log('Setup completed!'),
  )

  PointSdkRn.setupHealthkitIntegration(
    [
      QueryType.HeartRate,
      QueryType.StepCount,
      QueryType.ActiveEnergyBurned,
      QueryType.BasalEnergyBurned,
      QueryType.Workout,
    ],
    () => console.log('Setup Health Kit completed!'),
  )

  return App
})

As HealthKit is only available on iOS devices, this function will have no effect on other devices, like MacOS or iPadOS.

import PointSdkRn from 'react-native-point-sdk'

try {
  await PointSdkRn.requestPermissions()
} catch (error) {
  console.error(error)
}

Listeners

Listeners are tools to keep track of new samples added to Apple's Health. They run on top of HealthKit's background delivery, so they are able to work even when your app is on background. When a listener is set, it wakes up your app whenever a process adds new samples of the specified type, and then syncs those to the Point database.

Start

You need to start the listeners you wish to run. This must be done as soon as possible, such as when the app finishes launching.

You can start listeners for all types you have set up the SDK with.

import PointSdkRn from 'react-native-point-sdk'

try {
  await PointSdkRn.startAllListeners()
} catch (error) {
  console.error(error)
}

⚠️ If you plan on supporting background listeners, set up all your types as soon as possible in application launch.

⚠️ For iOS 15 you must enable the HealthKit Background Delivery by adding the com.apple.developer.healthkit.background-delivery entitlement to your app.

⚠️ Since the listeners are meant to be started in application launch, on the very first usage/session the queries will fail and not stay alive. This is because you start background listeners before asking for user permissions. If you want to collect data in background from the first moment, we recommend also calling the start methods once after requesting user permissions.

Stop

Stopping a listener will make any changes made on Apple's Health unnoticeable.

You can stop all listeners:

import PointSdkRn from 'react-native-point-sdk'

try {
  await PointSdkRn.stopAllListeners()
} catch (error) {
  console.error(error)
}

⚠️ Avoid stopping the listeners in the application lifecycle. You are not required to stop them at any time and their lifecycles are handled by Point SDK. The listeners are automatically stopped on user logout and restarted on new logins. Only explicitly stop them on a special scenario.

Next Steps

Learn more about the Fitbit integration.

Connect with Us

Terms & Conditions | Privacy Policy © 2023 Point® (Key Point Technologies, Inc.)