readQuantityDataWithType(params: Object)

Requires:
HealthKit≥5.18.3@ray-js/ray≥1.6.17
Platforms:
iOS
import { health } from '@ray-js/ray';

const { readQuantityDataWithType } = health;

// Promise usage
try {
  const res = await readQuantityDataWithType({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

Description

Read Quantity health data by type and time range [iOS only]

Parameters

PropertyTypeRequiredDescription
permissionsstring[]NoPermission types (used by the API that requests read/write permissions). See the enumeration list below for specific values, e.g., ["1","2"]
readPermissionsstring[]NoRead permission types (used by the API that checks whether the user has previously authorized). See the enumeration list below for specific values, e.g., ["1","2"]
writePermissionsstring[]NoWrite permission types (used by the API that checks whether the user has previously authorized). See the enumeration list below for specific values, e.g., ["1","2"]
writePermissionnumberNoWrite permission type (used by the API for checking write permission). See the enumeration list below for specific values
valuenumberNoValue to write (the specific measurement for Quantity or Category data)
unitTypestringNoUnit to pass in, e.g., "mg/dL", "g", "cm", "count". Required when querying or writing Quantity data. For units corresponding to each data type, refer to Apple’s official HKTypeIdentifiers.h file
startTimenumberNoStart time, timestamp in seconds
endTimenumberNoEnd time, timestamp in seconds
typenumberNoData type to read/write (used by the read/write APIs). See the enumeration list below for specific values
complete() => voidNoCompletion callback (executed on both success and failure)
success(params: Object) => voidNoCallback on successful API call
fail(params: Object) => voidNoFailure callback
success callback parameters
PropertyTypeDescriptionHealthKit Since
Data read; an array in which each item is a dictionary, defined as follows: value: Integer The value read; meaning varies by type—see Apple’s official documentation startDate: Double Start timestamp of the entry endDate: Double End timestamp of the entryv5.18.4
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestring | numberError code
Error extension

Return Value

None

Error Code

Error CodeError Message
1AppleHealthParamsError

Examples

Read weight data for a specified time range

import { health } from '@ray-js/ray'

const endTime = Math.floor(Date.now() / 1000);
const startTime = endTime - 60 * 60;

health.readQuantityDataWithType({
  permissions: ["4"],
  readPermissions: ["4"],
  writePermissions: ["4"],
  writePermission: 4,
  value: 65.5,
  unitType: "kg",
  startTime,
  endTime,
  type: 4,
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});