diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.h b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.h index 52685003704620e12eee8f4147d0bd9789c935b8..235e9c6b3887a22d211c0784dc9fd15a62e39511 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.h +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.h @@ -10,5 +10,6 @@ @interface RCTAppleHealthKit (Methods_Activity) - (void)activity_getActiveEnergyBurned:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)activity_getBasalEnergyBurned:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.m index 0d6275146294aee0af0f97955f55c374d40b3785..03b2724c1d5085c90cfbc049994b66f6fa235b56 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.m @@ -42,4 +42,35 @@ }]; } +- (void)activity_getBasalEnergyBurned:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback +{ + HKQuantityType *basalEnergyType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBasalEnergyBurned]; + NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil]; + NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]]; + HKUnit *cal = [HKUnit kilocalorieUnit]; + + if(startDate == nil){ + callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]); + return; + } + NSPredicate * predicate = [RCTAppleHealthKit predicateForSamplesBetweenDates:startDate endDate:endDate]; + + [self fetchQuantitySamplesOfType:basalEnergyType + unit:cal + predicate:predicate + ascending:false + limit:HKObjectQueryNoLimit + completion:^(NSArray *results, NSError *error) { + if(results){ + callback(@[[NSNull null], results]); + return; + } else { + NSLog(@"error getting basal energy burned samples: %@", error); + callback(@[RCTMakeError(@"error getting basal energy burned samples", nil, nil)]); + return; + } + }]; + +} + @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit.m b/RCTAppleHealthKit/RCTAppleHealthKit.m index a0013f1a0d0a2afff53a455f7a273fe9ca43901f..f438808abae1160d4736c3cdd182370440e83c32 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit.m @@ -152,6 +152,11 @@ RCT_EXPORT_METHOD(getActiveEnergyBurned:(NSDictionary *)input callback:(RCTRespo [self activity_getActiveEnergyBurned:input callback:callback]; } +RCT_EXPORT_METHOD(getBasalEnergyBurned:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self activity_getBasalEnergyBurned:input callback:callback]; +} + RCT_EXPORT_METHOD(getBodyTemperatureSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self vitals_getBodyTemperatureSamples:input callback:callback]; diff --git a/README.md b/README.md index af40df099fedaf962606fe41a9cf87195553e5e2..ad755c98a41e7a633dbf63e5d9cc132f66e35074 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) => * [initStepCountObserver](https://github.com/terrillo/rn-apple-healthkit/wiki/initStepCountObserver()) * Read Methods * [getActiveEnergyBurned](https://github.com/terrillo/rn-apple-healthkit/wiki/getActiveEnergyBurned()) + * [getBasalEnergyBurned](https://github.com/terrillo/rn-apple-healthkit/wiki/getBasalEnergyBurned()) * [getBiologicalSex](https://github.com/terrillo/rn-apple-healthkit/wiki/getBiologicalSex()) * [getBloodGlucoseSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getbloodglucosesamples()) * [getBloodPressureSamples](https://github.com/terrillo/rn-apple-healthkit/wiki/getbloodpressuresamples()) @@ -127,7 +128,8 @@ The available Healthkit permissions to use with `initHealthKit` | Permission | Healthkit Identifier Type | Read | Write | |------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|------|-------| -| ActiveEnergyBurned | [HKCharacteristicTypeIdentifierActiveEnergyBurned](https://developer.apple.com/documentation/healthkit/hkquantitytypeidentifier/1615771-activeenergyburned?language=objc) | ✓ | | +| ActiveEnergyBurned | [HKQuantityTypeIdentifierActiveEnergyBurned](https://developer.apple.com/documentation/healthkit/hkquantitytypeidentifier/1615771-activeenergyburned?language=objc) | ✓ | | +| BasalEnergyBurned | [HKQuantityTypeIdentifierBasalEnergyBurned](https://developer.apple.com/documentation/healthkit/hkquantitytypeidentifier/1615512-basalenergyburned?language=objc) | ✓ | | | BiologicalSex | [HKCharacteristicTypeIdentifierBiologicalSex](https://developer.apple.com/reference/Healthkit/hkcharacteristictypeidentifierbiologicalsex?language=objc) | ✓ | | | BloodGlucose | [HKQuantityTypeIdentifierBloodGlucose](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierbloodglucose?language=objc) | ✓ | | | BloodPressureDiastolic | [HKQuantityTypeIdentifierBloodPressureDiastolic](https://developer.apple.com/documentation/healthkit/hkquantitytypeidentifierbloodpressurediastolic?language=objc) | ✓ | ✓ |