diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m index d8dd80453ef8cfc34575b38e57305fdec70fb996..a4ca6eb7465922dda46885fb2d05d26617ae3588 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 e4ae959ce14b76bcb7c755c394d682d008083f98..4fd645967be464deb179c8f30618c2a5fa7e3ce4 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