From bb2886e5e00c708d251c9944441d88f6f304a404 Mon Sep 17 00:00:00 2001 From: Terrillo Walls Date: Fri, 9 Nov 2018 17:55:21 -0600 Subject: [PATCH] Docs intergrated for support help --- README.md | 62 +++++++++++++-------------- docs/Home.md | 35 +++++++++++++++ docs/Installation.md | 12 ++++++ docs/Permissions.md | 21 +++++++++ docs/_isAvailable.md | 1 + docs/getActiveEnergyBurned().md | 18 ++++++++ docs/getBasalEnergyBurned().md | 16 +++++++ docs/getBiologicalSex().md | 23 ++++++++++ docs/getBloodGlucoseSamples().md | 22 ++++++++++ docs/getBloodPressureSamples().md | 28 ++++++++++++ docs/getBodyTemperatureSamples().md | 30 +++++++++++++ docs/getDailyStepCountSamples().md | 18 ++++++++ docs/getDateOfBirth().md | 18 ++++++++ docs/getDistanceCycling().md | 26 +++++++++++ docs/getDistanceWalkingRunning().md | 27 ++++++++++++ docs/getFlightsClimbed().md | 25 +++++++++++ docs/getHeartRateSamples().md | 26 +++++++++++ docs/getHeightSamples().md | 27 ++++++++++++ docs/getLatestBmi().md | 20 +++++++++ docs/getLatestBodyFatPercentage().md | 20 +++++++++ docs/getLatestHeight().md | 21 +++++++++ docs/getLatestLeanBodyMass().md | 20 +++++++++ docs/getLatestWeight().md | 27 ++++++++++++ docs/getRespiratoryRateSamples().md | 22 ++++++++++ docs/getSleepSamples().md | 29 +++++++++++++ docs/getStepCount().md | 24 +++++++++++ docs/getWeightSamples().md | 28 ++++++++++++ docs/initHealthKit().md | 30 +++++++++++++ docs/initStepCountObserver().md | 64 ++++++++++++++++++++++++++++ docs/isAvailable().md | 13 ++++++ docs/saveBmi().md | 16 +++++++ docs/saveHeight().md | 17 ++++++++ docs/saveMindfulSession().md | 19 +++++++++ docs/saveSteps().md | 23 ++++++++++ docs/saveWeight().md | 18 ++++++++ 35 files changed, 815 insertions(+), 31 deletions(-) create mode 100644 docs/Home.md create mode 100644 docs/Installation.md create mode 100644 docs/Permissions.md create mode 100644 docs/_isAvailable.md create mode 100644 docs/getActiveEnergyBurned().md create mode 100644 docs/getBasalEnergyBurned().md create mode 100644 docs/getBiologicalSex().md create mode 100644 docs/getBloodGlucoseSamples().md create mode 100644 docs/getBloodPressureSamples().md create mode 100644 docs/getBodyTemperatureSamples().md create mode 100644 docs/getDailyStepCountSamples().md create mode 100644 docs/getDateOfBirth().md create mode 100644 docs/getDistanceCycling().md create mode 100644 docs/getDistanceWalkingRunning().md create mode 100644 docs/getFlightsClimbed().md create mode 100644 docs/getHeartRateSamples().md create mode 100644 docs/getHeightSamples().md create mode 100644 docs/getLatestBmi().md create mode 100644 docs/getLatestBodyFatPercentage().md create mode 100644 docs/getLatestHeight().md create mode 100644 docs/getLatestLeanBodyMass().md create mode 100644 docs/getLatestWeight().md create mode 100644 docs/getRespiratoryRateSamples().md create mode 100644 docs/getSleepSamples().md create mode 100644 docs/getStepCount().md create mode 100644 docs/getWeightSamples().md create mode 100644 docs/initHealthKit().md create mode 100644 docs/initStepCountObserver().md create mode 100644 docs/isAvailable().md create mode 100644 docs/saveBmi().md create mode 100644 docs/saveHeight().md create mode 100644 docs/saveMindfulSession().md create mode 100644 docs/saveSteps().md create mode 100644 docs/saveWeight().md diff --git a/README.md b/README.md index c23a941..adc0a3c 100644 --- a/README.md +++ b/README.md @@ -88,47 +88,47 @@ AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) => - HKQuantityTypeIdentifierActiveEnergyBurned ## Wiki - * [Installation](https://github.com/terrillo/rn-apple-healthkit/wiki/Install) + * [Installation](docs/Install) * [Documentation](#documentation) * [Permissions](#permissions) * [Units](#units) * Base Methods - * [isAvailable](https://github.com/terrillo/rn-apple-healthkit/wiki/isAvailable()) - * [initHealthKit](https://github.com/terrillo/rn-apple-healthkit/wiki/initHealthKit()) + * [isAvailable](docs/isAvailable()) + * [initHealthKit](docs/initHealthKit()) * Realtime Methods - * [initStepCountObserver](https://github.com/terrillo/rn-apple-healthkit/wiki/initStepCountObserver()) + * [initStepCountObserver](docs/initStepCountObserver()) * Read Methods - * [getActiveEnergyBurned](https://github.com/terrillo/rn-apple-healthkit/wiki/getActiveEnergyBurned()) - * [getBasalEnergyBurned](https://github.com/terrillo/rn-apple-healthkit/wiki/getBasalEnergyBurned()) - * [getBiologicalSex](https://github.com/terrillo/rn-apple-healthkit/wiki/getBiologicalSex()) - * [getBloodGlucoseSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getbloodglucosesamples()) - * [getBloodPressureSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getbloodpressuresamples()) - * [getBodyTemperatureSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getbodytemperaturesamples()) + * [getActiveEnergyBurned](docs/getActiveEnergyBurned()) + * [getBasalEnergyBurned](docs/getBasalEnergyBurned()) + * [getBiologicalSex](docs/getBiologicalSex()) + * [getBloodGlucoseSamples](docs/getbloodglucosesamples()) + * [getBloodPressureSamples](docs/getbloodpressuresamples()) + * [getBodyTemperatureSamples](docs/getbodytemperaturesamples()) * [getDailyDistanceCyclingSamples]() * [getDailyDistanceWalkingRunningSamples]() * [getDailyFlightsClimbedSamples]() - * [getDailyStepCountSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getDailyStepCountSamples()) - * [getDateOfBirth](https://github.com/terrillo/rn-apple-healthkit/wiki/getDateOfBirth()) - * [getDistanceCycling](https://github.com/terrillo/rn-apple-healthkit/wiki/getdistancecycling()) - * [getDistanceWalkingRunning](https://github.com/terrillo/rn-apple-healthkit/wiki/getDistanceWalkingRunning()) - * [getFlightsClimbed](https://github.com/terrillo/rn-apple-healthkit/wiki/getflightsclimbed()) - * [getHeartRateSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getheartratesamples()) - * [getHeightSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getheightsamples()) - * [getLatestBmi](https://github.com/terrillo/rn-apple-healthkit/wiki/getlatestbmi()) - * [getLatestBodyFatPercentage](https://github.com/terrillo/rn-apple-healthkit/wiki/getlatestbodyfatpercentage()) - * [getLatestHeight](https://github.com/terrillo/rn-apple-healthkit/wiki/getlatestheight()) - * [getLatestLeanBodyMass](https://github.com/terrillo/rn-apple-healthkit/wiki/getlatestleanbodymass()) - * [getLatestWeight](https://github.com/terrillo/rn-apple-healthkit/wiki/getlatestweight()) - * [getRespiratoryRateSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getrespiratoryratesamples()) - * [getSleepSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getsleepsamples()) - * [getStepCount](https://github.com/terrillo/rn-apple-healthkit/wiki/getStepCount()) - * [getWeightSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getweightsamples()) + * [getDailyStepCountSamples](docs/getDailyStepCountSamples()) + * [getDateOfBirth](docs/getDateOfBirth()) + * [getDistanceCycling](docs/getdistancecycling()) + * [getDistanceWalkingRunning](docs/getDistanceWalkingRunning()) + * [getFlightsClimbed](docs/getflightsclimbed()) + * [getHeartRateSamples](docs/getheartratesamples()) + * [getHeightSamples](docs/getheightsamples()) + * [getLatestBmi](docs/getlatestbmi()) + * [getLatestBodyFatPercentage](docs/getlatestbodyfatpercentage()) + * [getLatestHeight](docs/getlatestheight()) + * [getLatestLeanBodyMass](docs/getlatestleanbodymass()) + * [getLatestWeight](docs/getlatestweight()) + * [getRespiratoryRateSamples](docs/getrespiratoryratesamples()) + * [getSleepSamples](docs/getsleepsamples()) + * [getStepCount](docs/getStepCount()) + * [getWeightSamples](docs/getweightsamples()) * Write Methods - * [saveBmi](https://github.com/terrillo/rn-apple-healthkit/wiki/savebmi()) - * [saveHeight](https://github.com/terrillo/rn-apple-healthkit/wiki/saveheight()) - * [saveMindfulSession](https://github.com/terrillo/rn-apple-healthkit/wiki/saveMindfulSession()) - * [saveWeight](https://github.com/terrillo/rn-apple-healthkit/wiki/saveweight()) - * [saveSteps](https://github.com/terrillo/rn-apple-healthkit/wiki/saveSteps()) + * [saveBmi](docs/savebmi()) + * [saveHeight](docs/saveheight()) + * [saveMindfulSession](docs/saveMindfulSession()) + * [saveWeight](docs/saveweight()) + * [saveSteps](docs/saveSteps()) * [References](#references) ## Supported Apple Permissions diff --git a/docs/Home.md b/docs/Home.md new file mode 100644 index 0000000..de72de7 --- /dev/null +++ b/docs/Home.md @@ -0,0 +1,35 @@ +# React Native Apple Healthkit +A React Native bridge module for interacting with [Apple Healthkit](https://developer.apple.com/Healthkit/) data. + +* Base Methods + * [isAvailable](https://github.com/terrillo/rn-apple-healthkit/wiki/isAvailable()) + * [initHealthKit](https://github.com/terrillo/rn-apple-healthkit/wiki/initHealthKit()) +* Realtime Methods + * [initStepCountObserver](https://github.com/terrillo/rn-apple-healthkit/wiki/initStepCountObserver()) +* Read Methods + * [getBiologicalSex](https://github.com/terrillo/rn-apple-healthkit/wiki/getBiologicalSex()) + * [getBloodGlucoseSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getbloodglucosesamples()) + * [getBloodPressureSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getbloodpressuresamples()) + * [getBodyTemperatureSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getbodytemperaturesamples()) + * [getDailyStepCountSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getDailyStepCountSamples()) + * [getDateOfBirth](https://github.com/terrillo/rn-apple-healthkit/wiki/getDateOfBirth()) + * [getDistanceCycling](https://github.com/terrillo/rn-apple-healthkit/wiki/getdistancecycling()) + * [getDistanceWalkingRunning](https://github.com/terrillo/rn-apple-healthkit/wiki/getDistanceWalkingRunning()) + * [getFlightsClimbed](https://github.com/terrillo/rn-apple-healthkit/wiki/getflightsclimbed()) + * [getHeartRateSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getheartratesamples()) + * [getHeightSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getheightsamples()) + * [getLatestBmi](https://github.com/terrillo/rn-apple-healthkit/wiki/getlatestbmi()) + * [getLatestBodyFatPercentage](https://github.com/terrillo/rn-apple-healthkit/wiki/getlatestbodyfatpercentage()) + * [getLatestHeight](https://github.com/terrillo/rn-apple-healthkit/wiki/getlatestheight()) + * [getLatestLeanBodyMass](https://github.com/terrillo/rn-apple-healthkit/wiki/getlatestleanbodymass()) + * [getLatestWeight](https://github.com/terrillo/rn-apple-healthkit/wiki/getlatestweight()) + * [getRespiratoryRateSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getrespiratoryratesamples()) + * [getSleepSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getsleepsamples()) + * [getStepCount](https://github.com/terrillo/rn-apple-healthkit/wiki/getStepCount()) + * [getWeightSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getweightsamples()) +* Write Methods + * [saveBmi](https://github.com/terrillo/rn-apple-healthkit/wiki/savebmi()) + * [saveHeight](https://github.com/terrillo/rn-apple-healthkit/wiki/saveheight()) + * [saveMindfulSession](https://github.com/terrillo/rn-apple-healthkit/wiki/saveMindfulSession()) + * [saveWeight](https://github.com/terrillo/rn-apple-healthkit/wiki/saveweight()) + * [saveSteps](https://github.com/terrillo/rn-apple-healthkit/wiki/saveSteps()) diff --git a/docs/Installation.md b/docs/Installation.md new file mode 100644 index 0000000..a03d374 --- /dev/null +++ b/docs/Installation.md @@ -0,0 +1,12 @@ +Install the `rn-apple-healthkit` npm package + +- Run `npm install rn-apple-healthkit --save` +- Run `react-native link rn-apple-healthkit` + +Update `info.plist` in your React Native project +``` +NSHealthShareUsageDescription +Read and understand health data. +NSHealthUpdateUsageDescription +Share workout data with other apps. +``` diff --git a/docs/Permissions.md b/docs/Permissions.md new file mode 100644 index 0000000..9756c54 --- /dev/null +++ b/docs/Permissions.md @@ -0,0 +1,21 @@ +These permissions are exported as constants of the `rn-apple-healthkit` module. + +```javascript +import AppleHealthKit from 'rn-apple-healthkit'; + +// get the available permissions from AppleHealthKit.Constants object +const PERMS = AppleHealthKit.Constants.Permissions; + +// setup healthkit read/write permissions using PERMS +const healthKitOptions = { + permissions: { + read: [ + PERMS.StepCount, + PERMS.Height, + ], + write: [ + PERMS.StepCount + ], + } +}; +``` \ No newline at end of file diff --git a/docs/_isAvailable.md b/docs/_isAvailable.md new file mode 100644 index 0000000..2e65efe --- /dev/null +++ b/docs/_isAvailable.md @@ -0,0 +1 @@ +a \ No newline at end of file diff --git a/docs/getActiveEnergyBurned().md b/docs/getActiveEnergyBurned().md new file mode 100644 index 0000000..76f303f --- /dev/null +++ b/docs/getActiveEnergyBurned().md @@ -0,0 +1,18 @@ +A quantity sample type that measures the amount of active energy the user has burned. + +```javascript +let d = new Date(2016,1,1); +let options = { + startDate: (new Date(2016,10,1)).toISOString(), // required + endDate: (new Date()).toISOString(), // optional; default now +}; +``` + +```javascript +AppleHealthkit.getActiveEnergyBurned(options: Object, (err: Object, results: Object) => { + if (err) { + return; + } + console.log(results) +}); +``` \ No newline at end of file diff --git a/docs/getBasalEnergyBurned().md b/docs/getBasalEnergyBurned().md new file mode 100644 index 0000000..c9fb2b8 --- /dev/null +++ b/docs/getBasalEnergyBurned().md @@ -0,0 +1,16 @@ +```javascript +let d = new Date(2016,1,1); +let options = { + startDate: (new Date(2018,10,1)).toISOString(), // required + endDate: (new Date()).toISOString(), // optional; default now +}; +``` + +```javascript +AppleHealthkit.getBasalEnergyBurned(options: Object, (err: Object, results: Object) => { + if (err) { + return; + } + console.log(results) +}); +``` diff --git a/docs/getBiologicalSex().md b/docs/getBiologicalSex().md new file mode 100644 index 0000000..04decd2 --- /dev/null +++ b/docs/getBiologicalSex().md @@ -0,0 +1,23 @@ +Get the biological sex (gender). If the `BiologicalSex` read permission is missing or the user has denied it then the value will be `unknown`. The possible values are: + +| Value | HKBiologicalSex | +|---------|-----------------------| +| unknown | HKBiologicalSexNotSet | +| male | HKBiologicalSexMale | +| female | HKBiologicalSexFemale | +| other | HKBiologicalSexOther | + +```javascript +AppleHealthkit.getBiologicalSex(null, (err: Object, results: Object) => { + if (this._handleHealthkitError(err, 'getBiologicalSex')) { + return; + } + console.log(results) +}); +``` + +```javascript +{ + value: 'female', +} +``` \ No newline at end of file diff --git a/docs/getBloodGlucoseSamples().md b/docs/getBloodGlucoseSamples().md new file mode 100644 index 0000000..acb2dea --- /dev/null +++ b/docs/getBloodGlucoseSamples().md @@ -0,0 +1,22 @@ +Query for blood glucose samples. the options object is used to setup a query to retrieve relevant samples. +```javascript +let options = { + unit: 'mmolPerL', // optional; default 'mmolPerL' + startDate: (new Date(2016,4,27)).toISOString(), // required + endDate: (new Date()).toISOString(), // optional; default now + ascending: false, // optional; default false + limit:10, // optional; default no limit +}; +``` +Available units are: `'mmolPerL'`, `'mgPerdL'`. + +The callback function will be called with a `samples` array containing objects with *value*, *startDate*, and *endDate* fields + +```javascript +AppleHealthkit.getBloodGlucoseSamples(options, (err: Object, results: Array) => { + if (err) { + return; + } + console.log(results) +}); +``` diff --git a/docs/getBloodPressureSamples().md b/docs/getBloodPressureSamples().md new file mode 100644 index 0000000..10e94f8 --- /dev/null +++ b/docs/getBloodPressureSamples().md @@ -0,0 +1,28 @@ +Query for blood pressure samples. the options object is used to setup a query to retrieve relevant samples. +```javascript +let options = { + unit: 'mmhg', // optional; default 'mmhg' + startDate: (new Date(2016,4,27)).toISOString(), // required + endDate: (new Date()).toISOString(), // optional; default now + ascending: false, // optional; default false + limit:10, // optional; default no limit +}; +``` + +The callback function will be called with a `samples` array containing objects with *bloodPressureSystolicValue*, *bloodPressureDiastolicValue*, *startDate*, and *endDate* fields + +```javascript +AppleHealthkit.getBloodPressureSamples(options, (err: Object, results: Array) => { + if (err) { + return; + } + console.log(results) +}); +``` + +```javascript +[ + { bloodPressureSystolicValue: 120, bloodPressureDiastolicValue: 81, startDate:'2016-06-29T17:55:00.000-0400', endDate:'2016-06-29T17:55:00.000-0400' }, + { bloodPressureSystolicValue: 119, bloodPressureDiastolicValue: 77, startDate:'2016-03-12T13:22:00.000-0400', endDate:'2016-03-12T13:22:00.000-0400' }, +] +``` \ No newline at end of file diff --git a/docs/getBodyTemperatureSamples().md b/docs/getBodyTemperatureSamples().md new file mode 100644 index 0000000..375fcab --- /dev/null +++ b/docs/getBodyTemperatureSamples().md @@ -0,0 +1,30 @@ +Query for body temperature samples. the options object is used to setup a query to retrieve relevant samples. + +```javascript +let options = { + unit: 'celsius', // optional; default 'celsius' + startDate: (new Date(2016,4,27)).toISOString(), // required + endDate: (new Date()).toISOString(), // optional; default now + ascending: false, // optional; default false + limit:10, // optional; default no limit +}; +``` +Available units are: `'fahrenheit'`, `'celsius'`. + +The callback function will be called with a `samples` array containing objects with *value*, *startDate*, and *endDate* fields. + +```javascript +AppleHealthkit.getBodyTemperatureSamples(options, (err: Object, results: Array) => { + if (err) { + return; + } + console.log(results) +}); +``` + +```javascript +[ + { value: 74.02, startDate:'2016-06-29T17:55:00.000-0400', endDate:'2016-06-29T17:55:00.000-0400' }, + { value: 74, startDate:'2016-03-12T13:22:00.000-0400', endDate:'2016-03-12T13:22:00.000-0400' }, +] +``` \ No newline at end of file diff --git a/docs/getDailyStepCountSamples().md b/docs/getDailyStepCountSamples().md new file mode 100644 index 0000000..5d6f670 --- /dev/null +++ b/docs/getDailyStepCountSamples().md @@ -0,0 +1,18 @@ +Get the total steps per day over a specified date range. + +`getDailyStepCountSamples` accepts an options object containing required *`startDate: ISO8601Timestamp`* and optional *`endDate: ISO8601Timestamp`*. If `endDate` is not provided it will default to the current time +```javascript +let options = { + startDate: (new Date(2016,1,1)).toISOString() // required + endDate: (new Date()).toISOString() // optional; default now +}; +``` + +```javascript + AppleHealthkit.getDailyStepCountSamples(options: Object, (err: Object, results: Array) => { + if (this._handleHealthkitError(err, 'getDailyStepCountSamples')) { + return; + } + console.log(results) +}); +``` \ No newline at end of file diff --git a/docs/getDateOfBirth().md b/docs/getDateOfBirth().md new file mode 100644 index 0000000..32712c5 --- /dev/null +++ b/docs/getDateOfBirth().md @@ -0,0 +1,18 @@ +Get the date of birth. + +On success, the callback function will be provided with a `res` object containing dob `value: string` (ISO timestamp), and `age: number` (age in years): +```javascript +AppleHealthkit.getDateOfBirth(null, (err: Object, results: Object) => { + if (this._handleHealthkitError(err, 'getDateOfBirth')) { + return; + } + console.log(results) +}); +``` + +```javascript +{ + value: '1986-09-01T00:00:00.000-0400', + age: 29 +} +``` \ No newline at end of file diff --git a/docs/getDistanceCycling().md b/docs/getDistanceCycling().md new file mode 100644 index 0000000..4bc6fef --- /dev/null +++ b/docs/getDistanceCycling().md @@ -0,0 +1,26 @@ +Get the total distance cycling on a specific day. + +`getDistanceCycling` accepts an options object containing optional *`date: ISO8601Timestamp`* and *`unit: string`*. If `date` is not provided it will default to the current time. `unit` defaults to `meter` +```javascript +let options = { + unit: 'mile', // optional; default 'meter' + date: (new Date(2016,5,1)).toISOString(), // optional; default now +}; +``` + +```javascript +AppleHealthkit.getDistanceCycling(options: Object, (err: Object, results: Object) => { + if (err) { + return; + } + console.log(results) +}); +``` + +```javascript +{ + value: 11.45, + startDate: '2016-07-08T12:00:00.000-0400', + endDate: '2016-07-08T12:00:00.000-0400' +} +``` \ No newline at end of file diff --git a/docs/getDistanceWalkingRunning().md b/docs/getDistanceWalkingRunning().md new file mode 100644 index 0000000..89b47fb --- /dev/null +++ b/docs/getDistanceWalkingRunning().md @@ -0,0 +1,27 @@ +Get the total distance walking/running on a specific day. + +`getDistanceWalkingRunning` accepts an options object containing optional *`date: ISO8601Timestamp`* and *`unit: string`*. If `date` is not provided it will default to the current time. `unit` defaults to `meter`. + +```javascript +let options = { + unit: 'mile', // optional; default 'meter' + date: (new Date(2016,5,1)).toISOString(), // optional; default now +}; +``` + +```javascript +AppleHealthkit.getDistanceWalkingRunning(options: Object, (err: Object, results: Object) => { + if (err) { + return; + } + console.log(results) +}); +``` + +```javascript +{ + value: 1.45, + startDate: '2016-07-08T12:00:00.000-0400', + endDate: '2016-07-08T12:00:00.000-0400' +} +``` \ No newline at end of file diff --git a/docs/getFlightsClimbed().md b/docs/getFlightsClimbed().md new file mode 100644 index 0000000..d279d48 --- /dev/null +++ b/docs/getFlightsClimbed().md @@ -0,0 +1,25 @@ +get the total flights climbed (1 flight is ~10ft of elevation) on a specific day. + +`getFlightsClimbed` accepts an options object containing optional *`date: ISO8601Timestamp`*. if `date` is not provided it will default to the current time. +```javascript +let options = { + date: (new Date(2016,5,1)).toISOString(), // optional; default now +}; +``` + +```javascript +AppleHealthkit.getFlightsClimbed(options: Object, (err: Object, results: Object) => { + if (err) { + return; + } + console.log(results) +}); +``` + +```javascript +{ + value: 15, + startDate: '2016-07-08T12:00:00.000-0400', + endDate: '2016-07-08T12:00:00.000-0400' +} +``` \ No newline at end of file diff --git a/docs/getHeartRateSamples().md b/docs/getHeartRateSamples().md new file mode 100644 index 0000000..e7b1253 --- /dev/null +++ b/docs/getHeartRateSamples().md @@ -0,0 +1,26 @@ +Query for heart rate samples. the options object is used to setup a query to retrieve relevant samples. +```javascript +let options = { + unit: 'bpm', // optional; default 'bpm' + startDate: (new Date(2016,4,27)).toISOString(), // required + endDate: (new Date()).toISOString(), // optional; default now + ascending: false, // optional; default false + limit:10, // optional; default no limit +}; +``` + +The callback function will be called with a `samples` array containing objects with *value*, *startDate*, and *endDate* fields +```javascript +AppleHealthkit.getHeartRateSamples(options, (err: Object, results: Array) => { + if (err) { + return; + } + console.log(results) +}); +``` + +```javascript +[ + { value: 74.02, startDate:'2016-06-29T17:55:00.000-0400', endDate:'2016-06-29T17:55:00.000-0400' }, + { value: 74, startDate:'2016-03-12T13:22:00.000-0400', endDate:'2016-03-12T13:22:00.000-0400' }, +] \ No newline at end of file diff --git a/docs/getHeightSamples().md b/docs/getHeightSamples().md new file mode 100644 index 0000000..84225ec --- /dev/null +++ b/docs/getHeightSamples().md @@ -0,0 +1,27 @@ +query for height samples. the options object is used to setup a query to retrieve relevant samples. +```javascript +let options = { + unit: 'inch', // optional; default 'inch' + startDate: (new Date(2016,4,27)).toISOString(), // required + endDate: (new Date()).toISOString(), // optional; default now + ascending: false, // optional; default false + limit:10, // optional; default no limit +}; +``` + +```javascript +AppleHealthkit.getHeightSamples(options, (err: Object, results: Array) => { + if (err) { + return; + } + console.log(results) +}); +``` + +The callback function will be called with a `samples` array containing objects with `value`, `startDate`, and `endDate` fields +```javascript +[ + { value: 74.02, startDate:'2016-06-29T17:55:00.000-0400', endDate:'2016-06-29T17:55:00.000-0400' }, + { value: 74, startDate:'2016-03-12T13:22:00.000-0400', endDate:'2016-03-12T13:22:00.000-0400' }, +] +``` \ No newline at end of file diff --git a/docs/getLatestBmi().md b/docs/getLatestBmi().md new file mode 100644 index 0000000..bd496f9 --- /dev/null +++ b/docs/getLatestBmi().md @@ -0,0 +1,20 @@ +Get the most recent BMI sample. + +On success, the callback function will be provided with a `bmi` object containing the BMI `value`, and the `startDate` and `endDate` of the sample. *Note: startDate and endDate will be the same as bmi samples are saved at a specific point in time.* +```javascript +AppleHealthkit.getLatestBmi(null, (err: string, results: Object) => { + if (err) { + console.log("error getting latest bmi data: ", err); + return; + } + console.log(results) +}); +``` + +```javascript +{ + value: 27.2, + startDate: '2016-07-08T12:00:00.000-0400', + endDate: '2016-07-08T12:00:00.000-0400' +} +``` diff --git a/docs/getLatestBodyFatPercentage().md b/docs/getLatestBodyFatPercentage().md new file mode 100644 index 0000000..100e7d1 --- /dev/null +++ b/docs/getLatestBodyFatPercentage().md @@ -0,0 +1,20 @@ +Get the most recent body fat percentage. The percentage value is a number between 0 and 100. + +On success, the callback function will be provided with a `bodyFatPercentage` object containing the body fat percentage `value`, and the `startDate` and `endDate` of the sample. *Note: startDate and endDate will be the same as bodyFatPercentage samples are saved at a specific point in time.* + +```javascript +AppleHealthkit.getLatestBodyFatPercentage(null, (err: Object, results: Object) => { + if (err) { + return; + } + console.log(results) +}); +``` + +```javascript +{ + value: 20, + startDate: '2016-07-08T12:00:00.000-0400', + endDate: '2016-07-08T12:00:00.000-0400' +} +``` \ No newline at end of file diff --git a/docs/getLatestHeight().md b/docs/getLatestHeight().md new file mode 100644 index 0000000..9658053 --- /dev/null +++ b/docs/getLatestHeight().md @@ -0,0 +1,21 @@ +Get the most recent height value. + +On success, the callback function will be provided with a `height` object containing the height `value`, and the `startDate` and `endDate` of the height sample. *Note: startDate and endDate will be the same as height samples are saved at a specific point in time.* + +```javascript +AppleHealthkit.getLatestHeight(null, (err: string, results: Object) => { + if (err) { + console.log("error getting latest height: ", err); + return; + } + console.log(results) +}); +``` + +```javascript +{ + value: 72, + startDate: '2016-07-08T12:00:00.000-0400', + endDate: '2016-07-08T12:00:00.000-0400' +} +``` \ No newline at end of file diff --git a/docs/getLatestLeanBodyMass().md b/docs/getLatestLeanBodyMass().md new file mode 100644 index 0000000..c6da935 --- /dev/null +++ b/docs/getLatestLeanBodyMass().md @@ -0,0 +1,20 @@ +Get the most recent lean body mass. The value is a number representing the weight in pounds (lbs) + +On success, the callback function will be provided with a `leanBodyMass` object containing the leanBodyMass `value`, and the `startDate` and `endDate` of the sample. *Note: startDate and endDate will be the same as leanBodyMass samples are saved at a specific point in time.* + +```javascript + AppleHealthkit.getLatestLeanBodyMass(null, (err: Object, results: Object) => { + if (err) { + return; + } + console.log(results) +}); +``` + +```javascript +{ + value: 176, + startDate: '2016-07-08T12:00:00.000-0400', + endDate: '2016-07-08T12:00:00.000-0400' +} +``` \ No newline at end of file diff --git a/docs/getLatestWeight().md b/docs/getLatestWeight().md new file mode 100644 index 0000000..1ab59ff --- /dev/null +++ b/docs/getLatestWeight().md @@ -0,0 +1,27 @@ +Get the most recent weight sample. + +On success, the callback function will be provided with a `weight` object containing the weight `value`, and the `startDate` and `endDate` of the weight sample. *Note: startDate and endDate will be the same as weight samples are saved at a specific point in time.* + +```javascript +let options = { + unit: 'pound' +}; +``` + +```javascript +AppleHealthkit.getLatestWeight(options, (err: string, results: Object) => { + if (err) { + console.log("error getting latest weight: ", err); + return; + } + console.log(results) +}); +``` + +```javascript +{ + value: 200, + startDate: '2016-07-08T12:00:00.000-0400', + endDate: '2016-07-08T12:00:00.000-0400' +} +``` diff --git a/docs/getRespiratoryRateSamples().md b/docs/getRespiratoryRateSamples().md new file mode 100644 index 0000000..61594e9 --- /dev/null +++ b/docs/getRespiratoryRateSamples().md @@ -0,0 +1,22 @@ +Query for respiratory rate samples. the options object is used to setup a query to retrieve relevant samples. + +```javascript +let options = { + unit: 'bpm', // optional; default 'bpm' + startDate: (new Date(2016,4,27)).toISOString(), // required + endDate: (new Date()).toISOString(), // optional; default now + ascending: false, // optional; default false + limit:10, // optional; default no limit +}; +``` + +The callback function will be called with a `samples` array containing objects with *value*, *startDate*, and *endDate* fields + +```javascript +AppleHealthkit.getRespiratoryRateSamples(options, (err: Object, results: Array) => { + if (err) { + return; + } + console.log(results) +}); +``` diff --git a/docs/getSleepSamples().md b/docs/getSleepSamples().md new file mode 100644 index 0000000..e009827 --- /dev/null +++ b/docs/getSleepSamples().md @@ -0,0 +1,29 @@ +Query for sleep samples. + +Each sleep sample represents a period of time with a startDate and an endDate. +the sample's value will be either `INBED` or `ASLEEP`. these values should overlap, +meaning that two (or more) samples represent a single nights sleep activity. see +[Healthkit SleepAnalysis] reference documentation + +The options object is used to setup a query to retrieve relevant samples. +The options must contain `startDate` and may also optionally include `endDate` +and `limit` options +```javascript +let options = { + startDate: (new Date(2016,10,1)).toISOString(), // required + endDate: (new Date()).toISOString(), // optional; default now + limit:10, // optional; default no limit +}; +``` + +The callback function will be called with a `samples` array containing objects +with *value*, *startDate*, and *endDate* fields + +```javascript +AppleHealthkit.getSleepSamples(options, (err: Object, results: Array) => { + if (err) { + return; + } + console.log(results). +}); +``` \ No newline at end of file diff --git a/docs/getStepCount().md b/docs/getStepCount().md new file mode 100644 index 0000000..b0984a4 --- /dev/null +++ b/docs/getStepCount().md @@ -0,0 +1,24 @@ +Get the aggregated total steps for a specific day (starting and ending at midnight). + +An optional options object may be provided containing `date` field representing the selected day. If `date` is not set or an options object is not provided then the current day will be used. +```javascript +let d = new Date(2016,1,1); +let options = { + date: d.toISOString() +}; +``` + +```javascript +AppleHealthkit.getStepCount(options: Object, (err: Object, results: Object) => { + if (err) { + return; + } + console.log(results) +}); +``` + +```javascript +{ + value: 213, +} +``` \ No newline at end of file diff --git a/docs/getWeightSamples().md b/docs/getWeightSamples().md new file mode 100644 index 0000000..1430592 --- /dev/null +++ b/docs/getWeightSamples().md @@ -0,0 +1,28 @@ +Query for weight samples. the options object is used to setup a query to retrieve relevant samples. + +```javascript +let options = { + unit: 'pound', // optional; default 'pound' + startDate: (new Date(2016,4,27)).toISOString(), // required + endDate: (new Date()).toISOString(), // optional; default now + ascending: false, // optional; default false + limit:10, // optional; default no limit +}; +``` + +```javascript +AppleHealthkit.getWeightSamples(options, (err: Object, results: Array) => { + if (err) { + return; + } + console.log(results) +}); +``` + +```javascript +[ + { value: 160, startDate: '2016-07-09T00:00:00.000-0400', endDate: '2016-07-10T00:00:00.000-0400' }, + { value: 161, startDate: '2016-07-08T00:00:00.000-0400', endDate: '2016-07-09T00:00:00.000-0400' }, + { value: 165, startDate: '2016-07-07T00:00:00.000-0400', endDate: '2016-07-08T00:00:00.000-0400' }, +] +``` \ No newline at end of file diff --git a/docs/initHealthKit().md b/docs/initHealthKit().md new file mode 100644 index 0000000..dc0882e --- /dev/null +++ b/docs/initHealthKit().md @@ -0,0 +1,30 @@ +Initialize Healthkit. This will show the Healthkit permissions prompt for any read/write permissions set in the required `options` object. + +Due to Apple's privacy model if an app user has previously denied a specific permission then they can not be prompted again for that same permission. The app user would have to go into the Apple Health app and grant the permission to your react-native app under *sources* tab. + +For any data that is read from Healthkit the status/error is the same for both. This privacy restriction results in having no knowledge of whether the permission was denied (make sure it's added to the permissions options object), or the data for the specific request was nil (ex. no steps recorded today). + +For any data written to Healthkit an authorization error can be caught. If an authorization error occurs you can prompt the user to set the specific permission or add the permission to the options object if not present. + +If new read/write permissions are added to the options object then the app user will see the Healthkit permissions prompt with the new permissions to allow. + +`initHealthKit` requires an options object with Healthkit permission settings +```javascript +let options = { + permissions: { + read: ["Height", "Weight", "StepCount", "DateOfBirth", "BodyMassIndex"], + write: ["Weight", "StepCount", "BodyMassIndex"] + } +}; +``` + +```javascript +AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) => { + if (err) { + console.log("error initializing Healthkit: ", err); + return; + } + // Healthkit is initialized... + // now safe to read and write Healthkit data... +}); +``` \ No newline at end of file diff --git a/docs/initStepCountObserver().md b/docs/initStepCountObserver().md new file mode 100644 index 0000000..1ea3ca5 --- /dev/null +++ b/docs/initStepCountObserver().md @@ -0,0 +1,64 @@ +Setup an HKObserverQuery for step count (HKQuantityTypeIdentifierStepCount) that will +trigger an event listenable on react-native `NativeAppEventEmitter` when the +Healthkit step count has changed. + +The `initStepCountObserver` method must be called before adding a listener to +NativeAppEventEmitter. After the step count observer has been initialized you can +listen to the NativeAppEventEmitter `change:steps` event and re-fetch relevent +step count data in the event handler. + +The `initStepCountObserver` method should be called after Healthkit has been +successfully initialized (AppleHealthkit.initHealthKit has been called without +error). + +```javascript +// import NativeAppEventEmitter from react-native +import { + Navigator, + View, + NativeAppEventEmitter, +} from 'react-native'; +``` + +```javascript +AppleHealthKit.initHealthKit(HKOPTIONS, (err, res) => { + if (this._handleHKError(err, 'initHealthKit')) { + return; + } + + // initialize the step count observer + AppleHealthKit.initStepCountObserver({}, () => {}); + + // add event listener for 'change:steps' and handle the + // event in the event handler function. + // + // when adding a listener, a 'subscription' object is + // returned that must be used to remove the listener + // when the component unmounts. The subscription object + // must be accessible to any function/method/instance + // that will be unsubscribing from the event. + this.sub = NativeAppEventEmitter.addListener( + 'change:steps', + (evt) => { + // a 'change:steps' event has been received. step + // count data should be re-fetched from Healthkit. + this._fetchStepCountData(); + } + ); + + // other tasks to perform after Healthkit has been + // initialized (fetch relevant Healthkit data). + this._fetchStepCountData(); + this._fetchOtherRelevantHealthkitData(); + // ... +}); + +... + +// when the component where the listener was added unmounts +// (or whenever the listener should be removed), call the +// 'remove' method of the subscription object. +componentWillUnmount() { + this.sub.remove(); +} +``` diff --git a/docs/isAvailable().md b/docs/isAvailable().md new file mode 100644 index 0000000..e83a165 --- /dev/null +++ b/docs/isAvailable().md @@ -0,0 +1,13 @@ +Check for Healthkit availability + +```javascript +import AppleHealthkit from 'rn-apple-healthkit'; + +AppleHealthKit.isAvailable((err: Object, available: boolean) => { + if (err) { + console.log("error initializing Healthkit: ", err); + return; + } + // Healthkit is available +}); +``` \ No newline at end of file diff --git a/docs/saveBmi().md b/docs/saveBmi().md new file mode 100644 index 0000000..3838079 --- /dev/null +++ b/docs/saveBmi().md @@ -0,0 +1,16 @@ +save a numeric BMI value to Healthkit + +`saveBmi` accepts an options object containing a numeric BMI value: +```javascript +let options = { + value: 27.2 +} +``` +```javascript +AppleHealthkit.saveBmi(options: Object, (err: Object, results: Object) => { + if (err) { + return; + } + // BMI successfully saved +}); +``` \ No newline at end of file diff --git a/docs/saveHeight().md b/docs/saveHeight().md new file mode 100644 index 0000000..e5c36d1 --- /dev/null +++ b/docs/saveHeight().md @@ -0,0 +1,17 @@ +save a numeric height value to Healthkit + +`saveHeight` accepts an options object containing a numeric height value: +```javascript +let options = { + value: 200 // Inches +} +``` + +```javascript +AppleHealthkit.saveHeight(options: Object, (err: Object, results: Object) => { + if (err) { + return; + } + // height successfully saved +}); +``` \ No newline at end of file diff --git a/docs/saveMindfulSession().md b/docs/saveMindfulSession().md new file mode 100644 index 0000000..4166912 --- /dev/null +++ b/docs/saveMindfulSession().md @@ -0,0 +1,19 @@ +Each mindfulness sample represents a period of time with a startDate and an endDate. +the options must contain `startDate` and `endDate` + +```javascript +let options = { + startDate: (new Date(2016,10,1)).toISOString(), // required + endDate: (new Date()).toISOString(), // optional; default now +}; + +``` + +``` +AppleHealthKit.saveMindfulSession(options, (err, res) => { + if (err) return { + return + } + console.log('Mindful session saved') +}); +``` \ No newline at end of file diff --git a/docs/saveSteps().md b/docs/saveSteps().md new file mode 100644 index 0000000..de1615f --- /dev/null +++ b/docs/saveSteps().md @@ -0,0 +1,23 @@ +Save a step count sample. + +A step count sample represents the number of steps during a specific period of time. A sample should be a precise as possible, with startDate and endDate representing the range of time the steps were taken in. + +`saveSteps` accepts an options object containing required *`value: number`*, *`startDate: ISO8601Timestamp`*, and *`endDate: ISO8601Timestamp`*. +```javascript +// startDate and endDate are 30 minutes apart. +// this means the step count value occurred within those 30 minutes. +let options = { + value: 100, + startDate: (new Date(2016,6,2,6,0,0)).toISOString(), + endDate: (new Date(2016,6,2,6,30,0)).toISOString() +}; +``` + +```javascript +AppleHealthkit.saveSteps(options, (err, res) => { + if (this._handleHKError(err, 'saveSteps')) { + return; + } + // step count sample successfully saved +}); +``` \ No newline at end of file diff --git a/docs/saveWeight().md b/docs/saveWeight().md new file mode 100644 index 0000000..70e2f9c --- /dev/null +++ b/docs/saveWeight().md @@ -0,0 +1,18 @@ +save a numeric weight value to Healthkit + +`saveWeight` accepts an options object containing a numeric weight value: +```javascript +let options = { + value: 200 +} +``` + +```javascript +AppleHealthkit.saveWeight(options: Object, (err: Object, results: Object) => { + if (err) { + console.log("error saving weight to Healthkit: ", err); + return; + } + // Done +}); +``` \ No newline at end of file -- 2.26.2