authStatusPermissions(params: Object)

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

const { authStatusPermissions } = health;

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

Description

Check whether the user has granted read and write permissions for Quantity data types [iOS only]

Parameters

PropertyTypeRequiredDescription
permissionsstring[]NoPermission types (used by the API for requesting 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 specific measurement for data of type Quantity or Category)
unitTypestringNoUnit to pass in, e.g., "mg/dL", "g", "cm", "count"; required when querying or writing Quantity-type data For unit mappings by data type, refer to Apple's official HKTypeIdentifiers.h file
startTimenumberNoStart time, timestamp in seconds
endTimenumberNoEnd time, timestamp in 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(params: Object) => voidNoCallback on successful API call
fail(params: Object) => voidNoFailure callback
success callback parameters
PropertyTypeDescriptionHealthKit Since
valuenumberAuthorization status: 1 means all passed-in types have requested the corresponding read/write permissions; 0 means at least one has not been requestedv5.18.4
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestring | numberError code
Error extension

Return Value

None

Error Code

Error CodeError Message
1AppleHealthParamsError

Examples

Query HealthKit read/write authorization status

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

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

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