@@ -11,7 +11,7 @@ A React Native bridge module for interacting with [Apple HealthKit] data.
*[Permissions](#permissions)
*[Methods](#methods)
*[isAvailable](#isavailable)
*[initHealthKit](#inithealthkit)
*[initHealthkit](#initHealthkit)
*[getBiologicalSex](#getbiologicalsex)
*[getDateOfBirth](#getdateofbirth)
*[getStepCount](#getstepcount)
...
...
@@ -40,35 +40,33 @@ A React Native bridge module for interacting with [Apple HealthKit] data.
*[Examples](#examples)
## References
- Apple HealthKit Documentation [https://developer.apple.com/healthkit/](https://developer.apple.com/healthkit/)
- Apple Healthkit Documentation [https://developer.apple.com/Healthkit/](https://developer.apple.com/Healthkit/)
## Getting started
### Installation
Install the [rn-apple-healthkit] package from npm:
Install the [rn-apple-Healthkit] package from npm:
`npm install rn-apple-healthkit --save`
`npm install rn-apple-Healthkit --save`
##### Xcode
1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`
2. Go to `node_modules` ➜ `rn-apple-healthkit` and add `RCTAppleHealthKit.xcodeproj`
3. In XCode, in the project navigator, select your project. Add `libRCTAppleHealthKit.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
4. Click `RCTAppleHealthKit.xcodeproj` in the project navigator and go the `Build Settings` tab. Make sure 'All' is toggled on (instead of 'Basic'). In the `Search Paths` section, look for `Header Search Paths` and make sure it contains both `$(SRCROOT)/../../react-native/React` and `$(SRCROOT)/../../../React` - mark both as `recursive`.
5. Enable HealthKit in your application's `Capabilities`
2. Go to `node_modules` ➜ `rn-apple-Healthkit` and add `RCTAppleHealthkit.xcodeproj`
3. In XCode, in the project navigator, select your project. Add `libRCTAppleHealthkit.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
4. Click `RCTAppleHealthkit.xcodeproj` in the project navigator and go the `Build Settings` tab. Make sure 'All' is toggled on (instead of 'Basic'). In the `Search Paths` section, look for `Header Search Paths` and make sure it contains both `$(SRCROOT)/../../react-native/React` and `$(SRCROOT)/../../../React` - mark both as `recursive`.
5. Enable Healthkit in your application's `Capabilities`
Initialize HealthKit. This will show the HealthKit permissions prompt for any read/write permissions set in the required `options` object.
#### **`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 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.
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.
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
`initHealthkit` requires an options object with Healthkit permission settings
// res.value will be one of the values from the above table (Value column)
// use res.value ...
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):
// use res.value ... (ex: '1986-09-01T12:20:30-04:00')
// use res.age ... (ex: 29)
});
```
___
#### **`getStepCount`**
...
...
@@ -258,21 +258,27 @@ Get the aggregated total steps for a specific day (starting and ending at midnig
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.
@@ -281,51 +287,43 @@ 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
@@ -447,20 +445,28 @@ 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
letoptions={
unit:'meter',// optional; default 'meter'
unit:'mile',// optional; default 'meter'
date:(newDate(2016,5,1)).toISOString(),// optional; default now
@@ -490,20 +504,18 @@ 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.*
console.log("error saving weight to Healthkit: ",err);
return;
}
// weight successfully saved
// Done
});
```
...
...
@@ -563,25 +586,25 @@ ___
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.*
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.*
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.*
// use bodyFatPercentage.value, bodyFatPercentage.startDate, etc ...
});
```
___
#### **`getLatestLeanBodyMass`**
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.*
the callback function will be called with a `samples` array containing objects with *bloodPressureSystolicValue*, *bloodPressureDiastolicValue*, *startDate*, and *endDate* fields