Commit 6d5dbe83 authored by Greg Wilson's avatar Greg Wilson

Merge branch 'master' of github.com-GregWilson:GregWilson/react-native-apple-healthkit

parents dc03fedd 679e051f
...@@ -16,7 +16,9 @@ A React Native bridge module for interacting with [Apple HealthKit] data. ...@@ -16,7 +16,9 @@ A React Native bridge module for interacting with [Apple HealthKit] data.
* [getLatestWeight](#getlatestweight) * [getLatestWeight](#getlatestweight)
* [saveWeight](#saveweight) * [saveWeight](#saveweight)
* [getLatestHeight](#getlatestheight) * [getLatestHeight](#getlatestheight)
* [saveHeight](#saveheight)
* [getLatestBmi](#getlatestbmi) * [getLatestBmi](#getlatestbmi)
* [saveBmi](#savebmi)
* [getLatestBodyFatPercentage](#getlatestbodyfatpercentage) * [getLatestBodyFatPercentage](#getlatestbodyfatpercentage)
* [getLatestLeanBodyMass](#getlatestleanbodymass) * [getLatestLeanBodyMass](#getlatestleanbodymass)
* [Examples](#examples) * [Examples](#examples)
...@@ -24,14 +26,19 @@ A React Native bridge module for interacting with [Apple HealthKit] data. ...@@ -24,14 +26,19 @@ A React Native bridge module for interacting with [Apple HealthKit] data.
## Getting started ## Getting started
### Installation (xcode) ### Installation
1. `npm install react-native-apple-healthkit@https://github.com/GregWilson/react-native-apple-healthkit.git --save` Install the package from npm:
2. In XCode, in the project navigator, right click `Libraries``Add Files to [your project's name]`
3. Go to `node_modules``react-native-apple-healthkit` and add `RCTAppleHealthKit.xcodeproj` `npm install react-native-apple-healthkit --save`
4. In XCode, in the project navigator, select your project. Add `libRCTAppleHealthKit.a` to your project's `Build Phases``Link Binary With Libraries`
5. 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`. ##### Xcode
5. Compile and have fun
1. In XCode, in the project navigator, right click `Libraries``Add Files to [your project's name]`
2. Go to `node_modules``react-native-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. Compile and run
### Usage ### Usage
...@@ -44,7 +51,7 @@ var AppleHealthKit = require('react-native-apple-healthkit'); ...@@ -44,7 +51,7 @@ var AppleHealthKit = require('react-native-apple-healthkit');
let healthKitOptions = { let healthKitOptions = {
permissions: { permissions: {
read: ["Height", "Weight", "Steps", "DateOfBirth", "BodyMassIndex"], read: ["Height", "Weight", "Steps", "DateOfBirth", "BodyMassIndex"],
write: ["Weight", "Steps"] write: ["Weight", "Steps", "BodyMassIndex"]
} }
}; };
...@@ -68,7 +75,7 @@ var _ = require('lodash'); ...@@ -68,7 +75,7 @@ var _ = require('lodash');
... ...
AppleHealthKit.getCurrentWeight(null, (err, weight) => { AppleHealthKit.getLatestWeight(null, (err, weight) => {
if(err){ if(err){
console.log("error getting current weight: ", err); console.log("error getting current weight: ", err);
return; return;
...@@ -80,7 +87,7 @@ AppleHealthKit.getCurrentWeight(null, (err, weight) => { ...@@ -80,7 +87,7 @@ AppleHealthKit.getCurrentWeight(null, (err, weight) => {
... ...
let myWeight = 200; let myWeight = 200;
AppleHealthKit.saveWeight({weight:myWeight}, (err, res) => { AppleHealthKit.saveWeight({value:myWeight}, (err, res) => {
if(err){ if(err){
console.log("error saving weight to healthkit: ", err); console.log("error saving weight to healthkit: ", err);
return; return;
...@@ -107,7 +114,7 @@ Read Permissions: ...@@ -107,7 +114,7 @@ Read Permissions:
BodyMassIndex HKQuantityTypeIdentifierBodyMassIndex BodyMassIndex HKQuantityTypeIdentifierBodyMassIndex
LeanBodyMass HKQuantityTypeIdentifierLeanBodyMass LeanBodyMass HKQuantityTypeIdentifierLeanBodyMass
Steps HKQuantityTypeIdentifierStepCount Steps HKQuantityTypeIdentifierStepCount
Sex HKCharacteristicTypeIdentifierBiologicalSex BiologicalSex HKCharacteristicTypeIdentifierBiologicalSex
DateOfBirth HKCharacteristicTypeIdentifierDateOfBirth DateOfBirth HKCharacteristicTypeIdentifierDateOfBirth
DietaryEnergy HKQuantityTypeIdentifierDietaryEnergyConsumed DietaryEnergy HKQuantityTypeIdentifierDietaryEnergyConsumed
ActiveEnergy HKQuantityTypeIdentifierActiveEnergyBurned ActiveEnergy HKQuantityTypeIdentifierActiveEnergyBurned
...@@ -144,7 +151,7 @@ initialize HealthKit. this will show the HealthKit permissions prompt for any re ...@@ -144,7 +151,7 @@ initialize HealthKit. this will show the HealthKit permissions prompt for any re
let healthKitOptions = { let healthKitOptions = {
permissions: { permissions: {
read: ["Height", "Weight", "Steps", "DateOfBirth", "BodyMassIndex"], read: ["Height", "Weight", "Steps", "DateOfBirth", "BodyMassIndex"],
write: ["Weight"] write: ["Weight", "Steps", "BodyMassIndex"]
} }
}; };
``` ```
...@@ -185,7 +192,7 @@ AppleHealthKit.getLatestWeight(null, (err: string, weight: number) => { ...@@ -185,7 +192,7 @@ AppleHealthKit.getLatestWeight(null, (err: string, weight: number) => {
return; return;
} }
weight = _.round(weight,1); weight = _.round(weight,1);
// do something with the weight... // use weight ...
}); });
``` ```
...@@ -194,12 +201,12 @@ ___ ...@@ -194,12 +201,12 @@ ___
#### **`saveWeight`** #### **`saveWeight`**
save a numeric weight value to HealthKit save a numeric weight value to HealthKit
`saveWeight` accepts an object containing a numeric weight value with the key *weight*: `saveWeight` accepts an options object containing a numeric weight value:
```javascript ```javascript
let saveOptions = {weight: 200} let options = {value: 200}
``` ```
```javascript ```javascript
AppleHealthKit.saveWeight(saveOptions, (err, res) => { AppleHealthKit.saveWeight(options, (err, res) => {
if(err){ if(err){
console.log("error saving weight to healthkit: ", err); console.log("error saving weight to healthkit: ", err);
return; return;
...@@ -218,9 +225,28 @@ AppleHealthKit.getLatestHeight(null, (err: string, height: number) => { ...@@ -218,9 +225,28 @@ AppleHealthKit.getLatestHeight(null, (err: string, height: number) => {
console.log("error getting latest height: ", err); console.log("error getting latest height: ", err);
return; return;
} }
// do something with the height value... // use height ...
}); });
``` ```
___
#### **`saveHeight`**
save a numeric height value to HealthKit
`saveHeight` accepts an options object containing a numeric height value:
```javascript
let options = {value: 200}
```
```javascript
AppleHealthKit.saveHeight(options, (err, res) => {
if(this._handleHealthKitError(err, 'saveHeight')){
return;
}
// height successfully saved
});
```
___ ___
#### **`getLatestBmi`** #### **`getLatestBmi`**
...@@ -241,6 +267,24 @@ AppleHealthKit.getLatestBmi(null, (err: string, bmi: Object) => { ...@@ -241,6 +267,24 @@ AppleHealthKit.getLatestBmi(null, (err: string, bmi: Object) => {
___ ___
#### **`saveBmi`**
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, (err, res) => {
if(this._handleHealthKitError(err, 'saveBmi')){
return;
}
// BMI successfully saved
});
```
___
#### **`getLatestBodyFatPercentage`** #### **`getLatestBodyFatPercentage`**
get the most recent body fat percentage. the percentage value is a number between 0 and 100 get the most recent body fat percentage. the percentage value is a number between 0 and 100
```javascript ```javascript
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment