diff --git a/Constants/Permissions.js b/Constants/Permissions.js
new file mode 100644
index 0000000000000000000000000000000000000000..927fe4b33fd449c5a96b1580907d9db1232eea1b
--- /dev/null
+++ b/Constants/Permissions.js
@@ -0,0 +1,33 @@
+/**
+ * Apple Health Permissions
+ * https://github.com/terrillo/rn-apple-healthkit#permissions
+ * @type {Object}
+ */
+export const Permissions = {
+ ActiveEnergyBurned: "ActiveEnergyBurned",
+ AppleExerciseTime: "AppleExerciseTime",
+ BasalEnergyBurned: "BasalEnergyBurned",
+ BiologicalSex: "BiologicalSex",
+ BloodGlucose: "BloodGlucose",
+ BloodPressureDiastolic: "BloodPressureDiastolic",
+ BloodPressureSystolic: "BloodPressureSystolic",
+ BodyFatPercentage: "BodyFatPercentage",
+ BodyMass: "BodyMass",
+ BodyMassIndex: "BodyMassIndex",
+ BodyTemperature: "BodyTemperature",
+ DateOfBirth: "DateOfBirth",
+ DietaryEnergy: "DietaryEnergy",
+ DistanceCycling: "DistanceCycling",
+ DistanceWalkingRunning: "DistanceWalkingRunning",
+ FlightsClimbed: "FlightsClimbed",
+ HeartRate: "HeartRate",
+ Height: "Height",
+ LeanBodyMass: "LeanBodyMass",
+ MindfulSession: "MindfulSession",
+ NikeFuel: "NikeFuel",
+ RespiratoryRate: "RespiratoryRate",
+ SleepAnalysis: "SleepAnalysis",
+ StepCount: "StepCount",
+ Steps: "Steps",
+ Weight: "Weight"
+}
diff --git a/Constants/Units.js b/Constants/Units.js
new file mode 100644
index 0000000000000000000000000000000000000000..0eb471ac042b39336fe458fe013cf5f00b541e82
--- /dev/null
+++ b/Constants/Units.js
@@ -0,0 +1,27 @@
+/**
+ * Units
+ * https://github.com/terrillo/rn-apple-healthkit#units
+ * @type {Object}
+ */
+export const Units = {
+ bpm: "bpm",
+ calorie: "calorie",
+ celsius: "celsius",
+ count: "count",
+ day: "day",
+ fahrenheit: "fahrenheit",
+ foot: "foot",
+ gram: "gram",
+ hour: "hour",
+ inch: "inch",
+ joule: "joule",
+ meter: "meter",
+ mgPerdL: "mgPerdL",
+ mile: "mile",
+ minute: "minute",
+ mmhg: "mmhg",
+ mmolPerL: "mmolPerL",
+ percent: "percent",
+ pound: "pound",
+ second: "second"
+}
diff --git a/README.md b/README.md
index c4fb2b771e5ed5b91caf2fac5b6cebca75efce33..4a1bb998796775a3bdb01bc448b216c140dbad34 100644
--- a/README.md
+++ b/README.md
@@ -2,48 +2,7 @@
# React Native Apple Healthkit
A React Native bridge module for interacting with [Apple Healthkit] data.
-## Table of Contents
- * [Getting Started](#getting-started)
- * [Installation](#installation)
- * [Usage](#usage)
- * [Documentation](#documentation)
- * [Permissions](#permissions)
- * [Methods](#methods)
- * [isAvailable](#isavailable)
- * [initHealthKit](#initHealthKit)
- * [getBiologicalSex](#getbiologicalsex)
- * [getDateOfBirth](#getdateofbirth)
- * [getStepCount](#getstepcount)
- * [getDailyStepCountSamples](#getdailystepcountsamples)
- * [initStepCountObserver](#initstepcountobserver)
- * [saveSteps](#savesteps)
- * [getDistanceWalkingRunning](#getdistancewalkingrunning)
- * [getDistanceCycling](#getdistancecycling)
- * [getFlightsClimbed](#getflightsclimbed)
- * [getLatestWeight](#getlatestweight)
- * [getWeightSamples](#getweightsamples)
- * [saveWeight](#saveweight)
- * [getLatestHeight](#getlatestheight)
- * [getHeightSamples](#getheightsamples)
- * [saveHeight](#saveheight)
- * [getLatestBmi](#getlatestbmi)
- * [saveBmi](#savebmi)
- * [getLatestBodyFatPercentage](#getlatestbodyfatpercentage)
- * [getLatestLeanBodyMass](#getlatestleanbodymass)
- * [getHeartRateSamples](#getheartratesamples)
- * [getBodyTemperatureSamples](#getbodytemperaturesamples)
- * [getBloodPressureSamples](#getbloodpressuresamples)
- * [getRespiratoryRateSamples](#getrespiratoryratesamples)
- * [getBloodGlucoseSamples](#getbloodglucosesamples)
- * [getSleepSamples](#getsleepsamples)
- * [saveMindfulSession](#saveMindfulSession)
-
-## References
-- Apple Healthkit Documentation [https://developer.apple.com/Healthkit/](https://developer.apple.com/Healthkit/)
-
-## Getting started
-
-### Installation
+## Installation
Install the [rn-apple-healthkit] package from npm:
@@ -58,7 +17,7 @@ Update `info.plist` in your React Native project
Share workout data with other apps.
```
-### Manual Installation
+## Manual Installation
1. Run `npm install rn-apple-healthkit --save`
2. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`
@@ -69,84 +28,107 @@ Update `info.plist` in your React Native project

7. Compile and run
-### Usage
-Just `import` the `rn-apple-healthkit` module and you're ready to go!
+## Get Started
+Initialize Healthkit. This will show the Healthkit permissions prompt for any read/write permissions set in the required `options` object.
-```javascript
-import AppleHealthkit from 'rn-apple-healthkit';
+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"]
}
};
-AppleHealthKit.isAvailable((err: Object, available: boolean) => {
- AppleHealthkit.initHealthKit(options: Object, (err: Object, results: Object) => {
- if (err) {
- console.log("error initializing Healthkit: ", err);
- return;
- }
- // Healthkit initialized...
- });
-});
-
```
-When the module has been successfully initialized you can read and write Healthkit data
-
```javascript
-import AppleHealthkit from 'rn-apple-healthkit';
-
-AppleHealthkit.initHealthKit(null: Object, (err: string, results: Object) => {
-
- ...
+import AppleHealthKit from 'rn-apple-healthkit';
- AppleHealthkit.getLatestWeight(null, (err: Object, weight: Object) => {
- if(err){
- console.log("error getting current weight: ", err);
- return;
- }
- // use weight.value
- });
+AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) => {
+ if (err) {
+ console.log("error initializing Healthkit: ", err);
+ return;
+ }
- ...
+ // Height Example
+ AppleHealthKit.getDateOfBirth(null, (err: Object, results: Object) => {
+ if (this._handleHealthkitError(err, 'getDateOfBirth')) {
+ return;
+ }
+ console.log(results)
+ });
- let options = {
- value: 200
- };
- AppleHealthkit.saveWeight(options: Object, (err: Object, results: Object) => {
- if (err) {
- console.log("error saving weight to Healthkit: ", err);
- return;
- }
- // weight successfully saved
- });
+});
+```
+```javascript
+{
+ value: '1986-09-01T00:00:00.000-0400',
+ age: 29
}
-
-
```
-
-## Documentation
-
-### Permissions
+## Wiki
+ * [Installation](https://github.com/terrillo/rn-apple-healthkit/wiki/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())
+ * 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())
+ * [References](#references)
+
+## Supported Apple Permissions
The available Healthkit permissions to use with `initHealthKit`
| Permission | Healthkit Identifier Type | Read | Write |
|------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|------|-------|
-| ActiveEnergyBurned | [HKQuantityTypeIdentifierActiveEnergyBurned](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifieractiveenergyburned?language=objc) | ✓ | ✓ |
-| AppleExerciseTime | [HKQuantityTypeIdentifierAppleExerciseTime](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierappleexercisetime?language=objc) | ✓ | |
-| BasalEnergyBurned | [HKQuantityTypeIdentifierBasalEnergyBurned](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierbasalenergyburned?language=objc) | ✓ | ✓ |
| BiologicalSex | [HKCharacteristicTypeIdentifierBiologicalSex](https://developer.apple.com/reference/Healthkit/hkcharacteristictypeidentifierbiologicalsex?language=objc) | ✓ | |
| BloodGlucose | [HKQuantityTypeIdentifierBloodGlucose](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierbloodglucose?language=objc) | ✓ | |
+| BloodPressureDiastolic | [HKQuantityTypeIdentifierBloodPressureDiastolic](https://developer.apple.com/documentation/healthkit/hkquantitytypeidentifierbloodpressurediastolic?language=objc) | ✓ | ✓ |
+| BloodPressureSystolic | [HKQuantityTypeIdentifierBloodPressureSystolic](https://developer.apple.com/documentation/healthkit/hkquantitytypeidentifierbloodpressuresystolic?language=objc) | ✓ | ✓ |
| BodyMassIndex | [HKQuantityTypeIdentifierBodyMassIndex](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierbodymassindex?language=objc) | ✓ | ✓ |
| BodyTemperature | [HKQuantityTypeIdentifierBodyTemperature](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierbodytemperature?language=objc) | ✓ | |
| DateOfBirth | [HKCharacteristicTypeIdentifierDateOfBirth](https://developer.apple.com/reference/Healthkit/hkcharacteristictypeidentifierdateofbirth?language=objc) | ✓ | |
-| DietaryEnergy | [HKQuantityTypeIdentifierDietaryEnergyConsumed](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierdietaryenergyconsumed?language=objc) | ✓ | ✓ |
| DistanceCycling | [HKQuantityTypeIdentifierDistanceCycling](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierdistancecycling?language=objc) | ✓ | ✓ |
| DistanceWalkingRunning | [HKQuantityTypeIdentifierDistanceWalkingRunning](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierdistancewalkingrunning?language=objc) | ✓ | ✓ |
| FlightsClimbed | [HKQuantityTypeIdentifierFlightsClimbed](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierflightsclimbed?language=objc) | ✓ | ✓ |
@@ -154,21 +136,16 @@ The available Healthkit permissions to use with `initHealthKit`
| Height | [HKQuantityTypeIdentifierHeight](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierheight?language=objc) | ✓ | ✓ |
| LeanBodyMass | [HKQuantityTypeIdentifierLeanBodyMass](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierleanbodymass?language=objc) | ✓ | ✓ |
| MindfulSession | [HKCategoryTypeIdentifierMindfulSession](https://developer.apple.com/reference/healthkit/hkcategorytypeidentifiermindfulsession?language=objc) | | ✓ |
-| NikeFuel | [HKQuantityTypeIdentifierNikeFuel](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifiernikefuel?language=objc) | ✓ | |
| RespiratoryRate | [HKQuantityTypeIdentifierRespiratoryRate](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierrespiratoryrate?language=objc) | ✓ | |
| SleepAnalysis | [HKCategoryTypeIdentifierSleepAnalysis](https://developer.apple.com/reference/Healthkit/hkcategorytypeidentifiersleepanalysis?language=objc) | ✓ | |
| StepCount | [HKQuantityTypeIdentifierStepCount](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierstepcount?language=objc) | ✓ | ✓ |
| Steps | [HKQuantityTypeIdentifierSteps](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifiersteps?language=objc) | ✓ | ✓ |
| Weight | [HKQuantityTypeIdentifierBodyMass](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierbodymass?language=objc) | ✓ | ✓ |
-| BloodPressureDiastolic | [HKQuantityTypeIdentifierBloodPressureDiastolic](https://developer.apple.com/documentation/healthkit/hkquantitytypeidentifierbloodpressurediastolic?language=objc) | ✓ | ✓ |
-| BloodPressureSystolic | [HKQuantityTypeIdentifierBloodPressureSystolic](https://developer.apple.com/documentation/healthkit/hkquantitytypeidentifierbloodpressuresystolic?language=objc) | ✓ | ✓ |
These permissions are exported as constants of the `rn-apple-healthkit` module.
```javascript
-import AppleHealthKit from 'react-native-apple-healthkit';
-
-...
+import AppleHealthKit from 'rn-apple-healthkit';
// get the available permissions from AppleHealthKit.Constants object
const PERMS = AppleHealthKit.Constants.Permissions;
@@ -185,807 +162,31 @@ const healthKitOptions = {
],
}
};
-
-...
-```
-
-
-Options
--------
-
-#### **`isAvailable`**
-Check if Healthkit is available on the device.
-```javascript
-import AppleHealthkit from 'rn-apple-healthkit';
-
-AppleHealthkit.isAvailable((err: Object, available: boolean) => {
- if (available) {
- // ...
- }
-});
-```
-___
-
-#### **`initHealthKit`**
-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...
-});
-```
-
-___
-
-#### **`getBiologicalSex`**
-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',
-}
-```
-
-___
-
-#### **`getDateOfBirth`**
-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
-}
-```
-
-___
-
-#### **`getStepCount`**
-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 (this._handleHealthkitError(err, 'getStepCount')) {
- return;
- }
- console.log(results)
-});
-```
-
-```javascript
-{
- value: 213,
-}
-```
-
-___
-
-#### **`getDailyStepCountSamples`**
-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