Commit 95dfdb0c authored by Greg Wilson's avatar Greg Wilson Committed by GitHub

Update README.md

parent 3350edab
...@@ -56,20 +56,19 @@ var AppleHealthKit = require('react-native-apple-healthkit'); ...@@ -56,20 +56,19 @@ var AppleHealthKit = require('react-native-apple-healthkit');
... ...
let healthKitOptions = { let options = {
permissions: { permissions: {
read: ["Height", "Weight", "Steps", "DateOfBirth", "BodyMassIndex"], read: ["Height", "Weight", "Steps", "DateOfBirth", "BodyMassIndex"],
write: ["Weight", "Steps", "BodyMassIndex"] write: ["Weight", "Steps", "BodyMassIndex"]
} }
}; };
AppleHealthKit.initHealthKit(healthKitOptions, (err, res) => { AppleHealthKit.initHealthKit(options: Object, (err: Object, res: Object) => {
if(err) { if(err) {
console.log("error initializing healthkit: ", err); console.log("error initializing healthkit: ", err);
return; return;
} }
console.log("HEALTHKIT INITIALIZED!"); // healthkit initialized...
// ...
}); });
...@@ -83,19 +82,18 @@ var _ = require('lodash'); ...@@ -83,19 +82,18 @@ var _ = require('lodash');
... ...
AppleHealthKit.getLatestWeight(null, (err, weight) => { AppleHealthKit.getLatestWeight(null, (err: Object, weight: number) => {
if(err){ if(err){
console.log("error getting current weight: ", err); console.log("error getting current weight: ", err);
return; return;
} }
weight = _.round(weight,1); // use weight ...
// do something with the weight...
}); });
... ...
let myWeight = 200; let options = {value: 200};
AppleHealthKit.saveWeight({value:myWeight}, (err, res) => { AppleHealthKit.saveWeight(options: Object, (err: Object, res: Object) => {
if(err){ if(err){
console.log("error saving weight to healthkit: ", err); console.log("error saving weight to healthkit: ", err);
return; return;
...@@ -154,7 +152,7 @@ Methods ...@@ -154,7 +152,7 @@ Methods
#### **`isAvailable`** #### **`isAvailable`**
check if HealthKit is available on the device check if HealthKit is available on the device
```javascript ```javascript
AppleHealthKit.isAvailable((err: string, available: bool) => { AppleHealthKit.isAvailable((err: Object, available: boolean) => {
if(available){ if(available){
// ... // ...
} }
...@@ -165,7 +163,7 @@ ___ ...@@ -165,7 +163,7 @@ ___
#### **`initHealthKit`** #### **`initHealthKit`**
initialize HealthKit. this will show the HealthKit permissions prompt for any read/write permissions set in the required `options` object. 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 under *sources* tab. 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)
...@@ -175,7 +173,7 @@ if new read/write permissions are added to the options object then the app user ...@@ -175,7 +173,7 @@ if new read/write permissions are added to the options object then the app user
`initHealthKit` requires an options object with HealthKit permission settings `initHealthKit` requires an options object with HealthKit permission settings
```javascript ```javascript
let healthKitOptions = { let options = {
permissions: { permissions: {
read: ["Height", "Weight", "Steps", "DateOfBirth", "BodyMassIndex"], read: ["Height", "Weight", "Steps", "DateOfBirth", "BodyMassIndex"],
write: ["Weight", "Steps", "BodyMassIndex"] write: ["Weight", "Steps", "BodyMassIndex"]
...@@ -184,7 +182,7 @@ let healthKitOptions = { ...@@ -184,7 +182,7 @@ let healthKitOptions = {
``` ```
```javascript ```javascript
AppleHealthKit.initHealthKit(healthKitOptions: object, (err: string, res: object) => { AppleHealthKit.initHealthKit(options: Object, (err: string, res: Object) => {
if(err) { if(err) {
console.log("error initializing healthkit: ", err); console.log("error initializing healthkit: ", err);
return; return;
...@@ -216,7 +214,7 @@ let d = new Date(2016,5,27); ...@@ -216,7 +214,7 @@ let d = new Date(2016,5,27);
let options = { let options = {
date: d.toISOString() date: d.toISOString()
}; };
AppleHealthKit.getStepCountForDay(options, (err, steps) => { AppleHealthKit.getStepCountForDay(options: Object, (err: Object, steps: number) => {
if(this._handleHealthKitError(err, 'getStepCountForDay')){ if(this._handleHealthKitError(err, 'getStepCountForDay')){
return; return;
} }
...@@ -238,7 +236,7 @@ let options = { ...@@ -238,7 +236,7 @@ let options = {
``` ```
the function will be called with an array of elements `res` containing date and step count information the function will be called with an array of elements `res` containing date and step count information
```javascript ```javascript
AppleHealthKit.getMultiDayStepCounts(options, (err: Object, res: Array<Array<string|number>>) => { AppleHealthKit.getMultiDayStepCounts(options: Object, (err: Object, res: Array<Array<string|number>>) => {
if(this._handleHealthKitError(err, 'getMultiDayStepCounts')){ if(this._handleHealthKitError(err, 'getMultiDayStepCounts')){
return; return;
} }
...@@ -262,7 +260,6 @@ AppleHealthKit.getLatestWeight(null, (err: string, weight: number) => { ...@@ -262,7 +260,6 @@ AppleHealthKit.getLatestWeight(null, (err: string, weight: number) => {
console.log("error getting latest weight: ", err); console.log("error getting latest weight: ", err);
return; return;
} }
weight = _.round(weight,1);
// use weight ... // use weight ...
}); });
``` ```
...@@ -277,7 +274,7 @@ save a numeric weight value to HealthKit ...@@ -277,7 +274,7 @@ save a numeric weight value to HealthKit
let options = {value: 200} let options = {value: 200}
``` ```
```javascript ```javascript
AppleHealthKit.saveWeight(options, (err, res) => { AppleHealthKit.saveWeight(options: Object, (err: Object, res: Object) => {
if(err){ if(err){
console.log("error saving weight to healthkit: ", err); console.log("error saving weight to healthkit: ", err);
return; return;
...@@ -310,7 +307,7 @@ save a numeric height value to HealthKit ...@@ -310,7 +307,7 @@ save a numeric height value to HealthKit
let options = {value: 200} let options = {value: 200}
``` ```
```javascript ```javascript
AppleHealthKit.saveHeight(options, (err, res) => { AppleHealthKit.saveHeight(options: Object, (err: Object, res: Object) => {
if(this._handleHealthKitError(err, 'saveHeight')){ if(this._handleHealthKitError(err, 'saveHeight')){
return; return;
} }
...@@ -346,7 +343,7 @@ save a numeric BMI value to HealthKit ...@@ -346,7 +343,7 @@ save a numeric BMI value to HealthKit
let options = {value: 27.2} let options = {value: 27.2}
``` ```
```javascript ```javascript
AppleHealthKit.saveBmi(options, (err, res) => { AppleHealthKit.saveBmi(options: Object, (err: Object, res: Object) => {
if(this._handleHealthKitError(err, 'saveBmi')){ if(this._handleHealthKitError(err, 'saveBmi')){
return; return;
} }
......
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