getWeight(options)
Reads body-weight records from the device’s health store. If needed, presents a permissions prompt to the user to request access to health data first, and then returns the records that match the options you provide.
options—AGetWeightOptionsobject to filter the records by time range, limit the number of records, and set the unit for the returned values. Passnullto use the defaults.
-
A Promise object that resolves as an array of
WeightRecordobjects. If no records match, the array is empty. -
A rejected promise returns a
HealthServiceFailureobject containing details about the error.
This function reads weight records from the device’s health store and returns them as an array.
- When records are read, the result is returned via a fulfilled promise. Handle successful results in a
thenclause. - If an error occurs, the error is returned via a rejected promise. Handle errors in a
catchclause. - If the user denies permission to read health data, the promise is rejected with a
HealthServiceFailure.codevalue ofUSER_DENIED_PERMISSION. - The device’s health store records weight without a unit. HealthService converts the returned values to the unit that you set in
preferredUnit. If you don’t set a unit, HealthService returns values in kilograms.
See Also