Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/kingstinct/react-native-healthkit/llms.txt

Use this file to discover all available pages before exploring further.

saveCorrelationSample

Save a correlation sample to HealthKit. Correlations combine multiple related samples (quantities or categories) into a single entity.

Signature

function saveCorrelationSample(
  typeIdentifier: CorrelationTypeIdentifier,
  samples: SampleForSaving[],
  start: Date,
  end: Date,
  metadata?: AnyMap
): Promise<CorrelationSample | undefined>

Parameters

typeIdentifier
CorrelationTypeIdentifier
required
The type of correlation to save:
  • 'HKCorrelationTypeIdentifierBloodPressure' - Blood pressure reading
  • 'HKCorrelationTypeIdentifierFood' - Food/nutrition entry
samples
SampleForSaving[]
required
Array of samples to include in the correlation. Can be quantity or category samples.For blood pressure, you need:
  • Systolic blood pressure (HKQuantityTypeIdentifierBloodPressureSystolic)
  • Diastolic blood pressure (HKQuantityTypeIdentifierBloodPressureDiastolic)
For food, you can include:
  • Dietary energy (calories)
  • Protein, carbs, fats
  • Various vitamins and minerals
start
Date
required
When the correlation was recorded
end
Date
required
End date of the correlation (usually same as start for point-in-time readings)
metadata
AnyMap
Optional metadata for the correlation. For food entries, you can include:
  • HKMetadataKeyFoodType (string) - Description of the food

Returns

correlation
Promise<CorrelationSample | undefined>
The saved correlation sample, or undefined if the save failed

Example: Blood Pressure

import { saveCorrelationSample } from '@kingstinct/react-native-healthkit'

const now = new Date()

// Save a blood pressure reading
const bloodPressure = await saveCorrelationSample(
  'HKCorrelationTypeIdentifierBloodPressure',
  [
    {
      quantityType: 'HKQuantityTypeIdentifierBloodPressureSystolic',
      quantity: 120,
      unit: 'mmHg',
      startDate: now,
      endDate: now,
    },
    {
      quantityType: 'HKQuantityTypeIdentifierBloodPressureDiastolic',
      quantity: 80,
      unit: 'mmHg',
      startDate: now,
      endDate: now,
    },
  ],
  now,
  now
)

if (bloodPressure) {
  console.log('Blood pressure saved:', bloodPressure.uuid)
}

Example: Food Entry

import { saveCorrelationSample } from '@kingstinct/react-native-healthkit'

const now = new Date()

// Save a food entry with nutritional information
const food = await saveCorrelationSample(
  'HKCorrelationTypeIdentifierFood',
  [
    {
      quantityType: 'HKQuantityTypeIdentifierDietaryEnergyConsumed',
      quantity: 350,
      unit: 'kcal',
      startDate: now,
      endDate: now,
    },
    {
      quantityType: 'HKQuantityTypeIdentifierDietaryProtein',
      quantity: 25,
      unit: 'g',
      startDate: now,
      endDate: now,
    },
    {
      quantityType: 'HKQuantityTypeIdentifierDietaryCarbohydrates',
      quantity: 45,
      unit: 'g',
      startDate: now,
      endDate: now,
    },
    {
      quantityType: 'HKQuantityTypeIdentifierDietaryFatTotal',
      quantity: 12,
      unit: 'g',
      startDate: now,
      endDate: now,
    },
  ],
  now,
  now,
  {
    HKMetadataKeyFoodType: 'Chicken Caesar Salad',
  }
)

if (food) {
  console.log('Food entry saved:', {
    uuid: food.uuid,
    foodType: food.metadataFoodType,
  })
}
You must request write authorization for the correlation type identifier and all quantity types you want to include before calling this function.
For blood pressure readings, both systolic and diastolic values are required. For food entries, at minimum include dietary energy (calories), but adding more nutritional information provides better health tracking.

Build docs developers (and LLMs) love