Apple HealthKit

Retrieve and display health and fitness data from users' Apple HealthKit within your Lovable application.

THIS SDK IS STILL VERY EXPERIMENTAL AND IN ALPHA, WE DO NOT SUGGEST USING THIS IN PRODUCTION YET AS IT IS NOT FULLY STABLE YET

Lovable Prompt
Lovable Prompt

Add native HealthKit access functionality to read and write users' health and fitness data including steps, heart rate, body mass, distance, and other health metrics using the Despia SDK from: https://www.npmjs.com/package/despia-native

First, install the package: npm install despia-native

Then import it: import despia from 'despia-native'

  1. Read HealthKit data using await despia('readhealthkit://HKQuantityTypeIdentifierStepCount', ['HKQuantityTypeIdentifierStepCount']) which returns a JSON object with the requested HealthKit key

  2. When accessing the data, use "dot notation" like .HKQuantityTypeIdentifierStepCount to retrieve the health data in a JSON object format. Here is an example of the structure returned:

const health = await despia('readhealthkit://HKQuantityTypeIdentifierStepCount', ['HKQuantityTypeIdentifierStepCount']);
console.log(health.HKQuantityTypeIdentifierStepCount); // Access "HKQuantityTypeIdentifierStepCount" variable set as object key, from the "health" const

// Expected output format:
{
  "HKQuantityTypeIdentifierStepCount": 8547
}
  1. Write HealthKit data using despia('writehealthkit://HKQuantityTypeIdentifierStepCount//10000') to save numeric values to HealthKit

Works with all valid HealthKit keys - simply use any valid HealthKit identifier as both the URL path and the array parameter. The identifier name becomes the key in the returned object.

For a complete list of all available HealthKit identifiers, refer to Apple's official documentation:

This feature requires native capabilities which will be fully provided by the "despia-native" npm package, no additional native libraries are needed!

Please follow the installation instructions for the "despia-native" npm package closely, and do not modify my instructions. Implementation as mentioned is critical.

How it works: The Despia SDK provides native bridge functionality to access and write Apple HealthKit data through async method calls. Read health data by specifying the HealthKit key you want to access, which returns as a JSON object with the key name. Write operations save numeric values to HealthKit.

Installation

Install the Despia package from NPM:

npm install despia-native

Usage

1. Import the SDK

import despia from 'despia-native';

2. Read HealthKit Data

Access Native HealthKit Data and process it:

// Read step count
const health = await despia("readhealthkit://HKQuantityTypeIdentifierStepCount", ["HKQuantityTypeIdentifierStepCount"]);
console.log(health.HKQuantityTypeIdentifierStepCount); // Access "HKQuantityTypeIdentifierStepCount" variable set as object key, from the "health" const

// Expected output format:
{
  "HKQuantityTypeIdentifierStepCount": 8547
}

3. Write HealthKit Data

Write numeric values to HealthKit:

// Example: Write step count
despia("writehealthkit://HKQuantityTypeIdentifierStepCount//10000");

Scheme Format

Read: readhealthkit://<HealthKitIdentifier>

Write: writehealthkit://<HealthKitIdentifier>//<numericValue>

Available HealthKit Identifiers

For a complete list of all available HealthKit identifiers, refer to Apple's official documentation:

Resources

  • NPM Package

  • View full NPM documentation for additional configuration options

Lovable Integration

This SDK is optimized for Lovable's prompt-based AI builder, enabling quick integration of native HealthKit access into your generated apps.

Need Help?

For additional support or questions, please contact our support team at support@despia.com

Updated on