readQuantityDataWithTypeSync(params: Object)

Requires:
HealthKit≥5.18.3@ray-js/ray≥1.6.17
Platforms:
iOS

Description

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

Parameters

PropertyTypeRequiredDescriptionHealthKit Since
permissionsstring[]NoPermission types (used by the API to request read/write permissions). See the enum list below for specific values. e.g., ["1","2"]v5.18.0
readPermissionsstring[]NoRead permission types (used by the API that checks whether the user has already authorized). See the enum list below for specific values. e.g., ["1","2"]v5.18.0
writePermissionsstring[]NoWrite permission types (used by the API that checks whether the user has already authorized). See the enum list below for specific values. e.g., ["1","2"]v5.18.0
writePermissionnumberNoWrite permission types (used by the API that checks whether write permission is granted). See the enum list below for specific values.v5.18.0
valuenumberNoValue to write (the specific measurement for Quantity or Category data types).v5.18.0
unitTypestringNoUnit to pass in, such as "mg/dL", "g", "cm", "count"; required when querying or writing Quantity-type data. For the units corresponding to each data type, refer to Apple’s official HKTypeIdentifiers.h file.v5.18.0
startTimenumberNoStart time, Unix timestamp in secondsv5.18.0
endTimenumberNoEnd time, Unix timestamp in secondsv5.18.0
typenumberNoData types to read/write (used by the data read/write APIs). See the enum list below for specific values.v5.18.0

Return Value

Type: Object↓
PropertyTypeDescriptionHealthKit Since
The data read is an array; each item in the array is an object, defined as follows value: Integer - the value read; meanings vary, see Apple’s official documentation startDate: Double - the start timestamp of the entry endDate: Double - the end timestamp of the entryv5.18.4

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);
  },
});