authCategoryRWPermissions(params: Object)

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

const { authCategoryRWPermissions } = health;

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

Description

Request read/write permissions for Category data types [iOS only]

Parameters

PropertyTypeRequiredDescription
permissionsstring[]NoPermission types (used by APIs that request read/write permissions); see the enum list below for specific values e.g. ["1","2"]
readPermissionsstring[]NoRead permission types (used by APIs that check whether the user has already authorized); see the enum list below for specific values e.g. ["1","2"]
writePermissionsstring[]NoWrite permission types (used by APIs that check whether the user has already authorized); see the enum list below for specific values e.g. ["1","2"]
writePermissionnumberNoWrite permission types (used by APIs that check whether write permission is granted); see the enum list below for specific values
valuenumberNoValue to write (the measurement value for Quantity or Category data types)
unitTypestringNoUnit to pass in, e.g., "mg/dL", "g", "cm", "count"; required when querying or writing Quantity data. Refer to Apple's official HKTypeIdentifiers.h for the units corresponding to each data type.
startTimenumberNoStart time, Unix timestamp (seconds)
endTimenumberNoEnd time, Unix timestamp (seconds)
typenumberNoData types to read/write (used by data read/write APIs); see the enum list below for specific values
complete() => voidNoCompletion callback (executed on both success and failure)
success() => voidNoCallback on successful API call
fail(params: Object) => voidNoFailure callback
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestring | numberError code
Error extension

Return Value

None

Error Code

Error CodeError Message
1AppleHealthParamsError

Examples

Request read/write permission for sleep analysis data

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

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

health.authCategoryRWPermissions({
  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);
  },
});