From 4d738c3837cb96da7ee5187ec2d027ba22273095 Mon Sep 17 00:00:00 2001 From: Greg Wilson Date: Sun, 6 Nov 2016 18:40:38 -0500 Subject: [PATCH] updated code and added documentation for getSleepSamples --- RCTAppleHealthKit/RCTAppleHealthKit+Queries.m | 19 +++++++-- README.md | 41 ++++++++++++++++++- .../ios/StepsDemo.xcodeproj/project.pbxproj | 30 ++++++++++++++ examples/StepsDemo/package.json | 3 +- 4 files changed, 87 insertions(+), 6 deletions(-) diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m index d8dd804..a4ca6eb 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m @@ -140,7 +140,7 @@ for (HKCategorySample *sample in results) { - HKCategoryType *catType = sample.categoryType; + // HKCategoryType *catType = sample.categoryType; NSInteger val = sample.value; // HKQuantity *quantity = sample.quantity; @@ -149,9 +149,22 @@ NSString *startDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.startDate]; NSString *endDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.endDate]; + NSString *valueString; + + switch (val) { + case HKCategoryValueSleepAnalysisInBed: + valueString = @"INBED"; + break; + case HKCategoryValueSleepAnalysisAsleep: + valueString = @"ASLEEP"; + break; + default: + valueString = @"UNKNOWN"; + break; + } + NSDictionary *elem = @{ - @"value" : @(( (float) val )), - @"catType" : catType.identifier, + @"value" : valueString, @"startDate" : startDateString, @"endDate" : endDateString, }; diff --git a/README.md b/README.md index e4ae959..4fd6459 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ A React Native bridge module for interacting with [Apple HealthKit] data. * [getBloodPressureSamples](#getbloodpressuresamples) * [getRespiratoryRateSamples](#getrespiratoryratesamples) * [getBloodGlucoseSamples](#getbloodglucosesamples) + * [getSleepSamples](#getsleepsamples) * [Examples](#examples) @@ -151,7 +152,10 @@ The available HealthKit permissions to use with `initHealthKit` | BloodPressureSystolic | [HKQuantityTypeIdentifierBloodPressureSystolic](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierbloodpressuresystolic?language=objc) | ✓ | | | BloodPressureDiastolic | [HKQuantityTypeIdentifierBloodPressureDiastolic](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierbloodpressurediastolic?language=objc) | ✓ | | | RespiratoryRate | [HKQuantityTypeIdentifierRespiratoryRate](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierrespiratoryrate?language=objc) | ✓ | | -| BloodGlucose | [HKQuantityTypeIdentifierBloodGlucose](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierbloodglucose?language=objc) | ✓ | | +| BloodGlucose | [HKQuantityTypeIdentifierBloodGlucose](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierbloodglucose?language=objc) | ✓ | +| +| SleepAnalysis | [HKCategoryTypeIdentifierSleepAnalysis](https://developer.apple.com/reference/healthkit/hkcategorytypeidentifiersleepanalysis?language=objc) | ✓ | +| These permissions are exported as constants of the `react-native-apple-healthkit` module. @@ -873,6 +877,40 @@ AppleHealthKit.getBloodGlucoseSamples(options, (err: Object, samples: Array) => { + if(this._handleHealthKitError(err, 'getSleepSamples')){ + return; + } + // use samples ... +}); +``` + ## Examples @@ -892,3 +930,4 @@ AppleHealthKit.getBloodGlucoseSamples(options, (err: Object, samples: Array