saveCategoryDataSync(params: Object)

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

Description

Write Category-type health data (including start and end times) [iOS only]

Parameters

PropertyTypeRequiredDescriptionHealthKit Since
permissionsstring[]NoPermission types (used by the API for requesting read/write permissions); see the enum list below for 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 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 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 valuesv5.18.0
valuenumberNoValue to write (specific measurement for Quantity or Category data)v5.18.0
unitTypestringNoUnit to pass in, e.g., "mg/dL", "g", "cm", "count"; required when querying and writing Quantity-type data. For the unit applicable to each data type, refer to Apple's HKTypeIdentifiers.h.v5.18.0
startTimenumberNoStart time, Unix timestamp in secondsv5.18.0
endTimenumberNoEnd time, Unix timestamp in secondsv5.18.0
typenumberNoData type to read/write (used by read/write APIs); see the enum list below for valuesv5.18.0

Return Value

None

Error Code

Error CodeError Message
1AppleHealthParamsError
2AppleHealthNoPermission

Examples

Write sleep analysis data at a specified time

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

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

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