Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
GGGava authored Jul 3, 2023
2 parents 504a3c9 + b1aaf5f commit 7ce15ab
Show file tree
Hide file tree
Showing 82 changed files with 4,716 additions and 2,744 deletions.
18 changes: 0 additions & 18 deletions .github/auto_assign.yml

This file was deleted.

5 changes: 5 additions & 0 deletions RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- (void)body_saveWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;

- (void)body_getLatestBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getBodyMassIndexSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_saveBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;

- (void)body_getLatestHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
Expand All @@ -25,6 +26,10 @@
- (void)body_getWaistCircumferenceSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_saveWaistCircumference:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;

- (void)body_getLatestPeakFlow:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getPeakFlowSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_savePeakFlow:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;

- (void)body_getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getBodyFatPercentageSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_saveBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
Expand Down
106 changes: 106 additions & 0 deletions RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,37 @@ - (void)body_getLatestBodyMassIndex:(NSDictionary *)input callback:(RCTResponseS
}];
}

- (void)body_getBodyMassIndexSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKQuantityType *bmiType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMassIndex];

HKUnit *countUnit = [HKUnit countUnit];
NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit];
BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false];
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil];
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
if(startDate == nil){
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
return;
}
NSPredicate * predicate = [RCTAppleHealthKit predicateForSamplesBetweenDates:startDate endDate:endDate];

[self fetchQuantitySamplesOfType:bmiType
unit:countUnit
predicate:predicate
ascending:ascending
limit:limit
completion:^(NSArray *results, NSError *error) {
if(results){
callback(@[[NSNull null], results]);
return;
} else {
callback(@[RCTJSErrorFromNSError(error)]);
return;
}
}];
}


- (void)body_saveBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
Expand Down Expand Up @@ -297,6 +328,81 @@ - (void)body_saveWaistCircumference:(NSDictionary *)input callback:(RCTResponseS
}];
}

- (void)body_getLatestPeakFlow:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKQuantityType *peakFlowType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierPeakExpiratoryFlowRate];
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[[HKUnit literUnit] unitDividedByUnit:[HKUnit minuteUnit]]];

[self fetchMostRecentQuantitySampleOfType:peakFlowType
predicate:nil
completion:^(HKQuantity *mostRecentQuantity, NSDate *startDate, NSDate *endDate, NSError *error) {
if (error) {
NSLog(@"error getting latest peak flow: %@", error);
callback(@[RCTMakeError(@"error getting latest peak flow", error, nil)]);
}
else {
// Determine the peak flow rate in the required unit.
double peakFlow = [mostRecentQuantity doubleValueForUnit:unit];

NSDictionary *response = @{
@"value" : @(peakFlow),
@"startDate" : [RCTAppleHealthKit buildISO8601StringFromDate:startDate],
@"endDate" : [RCTAppleHealthKit buildISO8601StringFromDate:endDate],
};

callback(@[[NSNull null], response]);
}
}];
}

- (void)body_getPeakFlowSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKQuantityType *peakFlowType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierPeakExpiratoryFlowRate];

HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[[HKUnit literUnit] unitDividedByUnit:[HKUnit minuteUnit]]];

NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit];
BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false];
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil];
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
if(startDate == nil){
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
return;
}
NSPredicate * predicate = [RCTAppleHealthKit predicateForSamplesBetweenDates:startDate endDate:endDate];

[self fetchQuantitySamplesOfType:peakFlowType
unit:unit
predicate:predicate
ascending:ascending
limit:limit
completion:^(NSArray *results, NSError *error) {
if(results){
callback(@[[NSNull null], results]);
} else {
callback(@[RCTJSErrorFromNSError(error)]);
}
}];
}

- (void)body_savePeakFlow:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
double peakFlow = [RCTAppleHealthKit doubleValueFromOptions:input];
NSDate *sampleDate = [RCTAppleHealthKit dateFromOptionsDefaultNow:input];
HKUnit *peakFlowUnit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[[HKUnit literUnit] unitDividedByUnit:[HKUnit minuteUnit]]];

HKQuantity *peakFlowQuantity = [HKQuantity quantityWithUnit:peakFlowUnit doubleValue:peakFlow];
HKQuantityType *peakFlowType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierPeakExpiratoryFlowRate];
HKQuantitySample *peakFlowSample = [HKQuantitySample quantitySampleWithType:peakFlowType quantity:peakFlowQuantity startDate:sampleDate endDate:sampleDate];

[self.healthStore saveObject:peakFlowSample withCompletion:^(BOOL success, NSError *error) {
if (!success) {
callback(@[RCTJSErrorFromNSError(error)]);
return;
}
callback(@[[NSNull null], @(peakFlow)]);
}];
}

- (void)body_getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
Expand Down
2 changes: 2 additions & 0 deletions RCTAppleHealthKit/RCTAppleHealthKit+Methods_Dietary.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

- (void)saveWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)getWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)getWaterSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;

- (void)dietary_getEnergyConsumedSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)dietary_getProteinSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)dietary_getFiberSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)dietary_getTotalFatSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
@end
66 changes: 66 additions & 0 deletions RCTAppleHealthKit/RCTAppleHealthKit+Methods_Dietary.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,37 @@ - (void)dietary_getProteinSamples:(NSDictionary *)input callback:(RCTResponseSen
}];
}

- (void)dietary_getFiberSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKQuantityType *fiberType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryFiber];
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit gramUnit]];
NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit];
BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false];
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil];
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
if(startDate == nil){
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
return;
}
NSPredicate * predicate = [RCTAppleHealthKit predicateForSamplesBetweenDates:startDate endDate:endDate];

[self fetchQuantitySamplesOfType:fiberType
unit:unit
predicate:predicate
ascending:ascending
limit:limit
completion:^(NSArray *results, NSError *error) {
if(results){
callback(@[[NSNull null], results]);
return;
} else {
NSLog(@"An error occured while retrieving the fiber sample %@. The error was: ", error);
callback(@[RCTMakeError(@"An error occured while retrieving the fiber sample", error, nil)]);
return;
}
}];
}

- (void)saveFood:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
NSString *foodNameValue = [RCTAppleHealthKit stringFromOptions:input key:@"foodName" withDefault:nil];
Expand Down Expand Up @@ -533,4 +564,39 @@ - (void)getWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
}];
}

- (void)getWaterSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKQuantityType *dietaryWaterType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryWater];
HKUnit *literUnit = [HKUnit literUnit];
NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit];
BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false];
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil];
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
BOOL includeManuallyAdded = [RCTAppleHealthKit boolFromOptions:input key:@"includeManuallyAdded" withDefault:true];


if(startDate == nil) {
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
return;
}

NSPredicate * predicate = [RCTAppleHealthKit predicateForSamplesBetweenDates:startDate endDate:endDate];

[self fetchQuantitySamplesOfType:dietaryWaterType
unit:literUnit
predicate:predicate
ascending:ascending
limit:limit
completion:^(NSArray *results, NSError *error) {
if(results){
callback(@[[NSNull null], results]);
return;
} else {
NSLog(@"An error occured while retrieving the water sample %@. The error was: ", error);
callback(@[RCTMakeError(@"An error occured while retrieving the water sample", error, nil)]);
return;
}
}];
}

@end
1 change: 1 addition & 0 deletions RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- (void)fitness_getSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_getDailyStepSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_saveSteps:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_saveWalkingRunningDistance:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_initializeStepEventObserver:(NSDictionary *)input hasListeners:(bool)hasListeners callback:(RCTResponseSenderBlock)callback;
- (void)fitness_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_getDailyDistanceWalkingRunningSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
Expand Down
36 changes: 31 additions & 5 deletions RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ - (void)fitness_getStepCountOnDay:(NSDictionary *)input callback:(RCTResponseSen
includeManuallyAdded:includeManuallyAdded
day:date
completion:^(double value, NSDate *startDate, NSDate *endDate, NSError *error) {
if (!value && value != 0) {
if ((!value && value != 0) || error != nil) {
callback(@[RCTJSErrorFromNSError(error)]);
return;
}
Expand Down Expand Up @@ -152,6 +152,32 @@ - (void)fitness_saveSteps:(NSDictionary *)input callback:(RCTResponseSenderBlock
}];
}

- (void)fitness_saveWalkingRunningDistance:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
double distance = [RCTAppleHealthKit doubleValueFromOptions:input];
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil];
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit meterUnit]];

if(startDate == nil || endDate == nil){
callback(@[RCTMakeError(@"startDate and endDate are required in options", nil, nil)]);
return;
}

HKQuantity *quantity = [HKQuantity quantityWithUnit:unit doubleValue:distance];
HKQuantityType *type = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning];
HKQuantitySample *sample = [HKQuantitySample quantitySampleWithType:type quantity:quantity startDate:startDate endDate:endDate];

[self.healthStore saveObject:sample withCompletion:^(BOOL success, NSError *error) {
if (!success) {
callback(@[RCTJSErrorFromNSError(error)]);
return;
}
callback(@[[NSNull null], @(distance)]);
}];
}



- (void)fitness_initializeStepEventObserver:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
Expand Down Expand Up @@ -192,7 +218,7 @@ - (void)fitness_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(R
HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning];

[self fetchSumOfSamplesOnDayForType:quantityType unit:unit includeManuallyAdded:includeManuallyAdded day:date completion:^(double distance, NSDate *startDate, NSDate *endDate, NSError *error) {
if (!distance && distance != 0) {
if ((!distance && distance != 0) || error != nil) {
callback(@[RCTJSErrorFromNSError(error)]);
return;
}
Expand Down Expand Up @@ -251,7 +277,7 @@ - (void)fitness_getDistanceSwimmingOnDay:(NSDictionary *)input callback:(RCTResp
HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceSwimming];

[self fetchSumOfSamplesOnDayForType:quantityType unit:unit includeManuallyAdded:includeManuallyAdded day:date completion:^(double distance, NSDate *startDate, NSDate *endDate, NSError *error) {
if (!distance && distance != 0) {
if ((!distance && distance != 0) || error != nil) {
callback(@[RCTJSErrorFromNSError(error)]);
return;
}
Expand Down Expand Up @@ -308,7 +334,7 @@ - (void)fitness_getDistanceCyclingOnDay:(NSDictionary *)input callback:(RCTRespo
HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceCycling];

[self fetchSumOfSamplesOnDayForType:quantityType unit:unit includeManuallyAdded:includeManuallyAdded day:date completion:^(double distance, NSDate *startDate, NSDate *endDate, NSError *error) {
if (!distance && distance != 0) {
if ((!distance && distance != 0) || error != nil) {
callback(@[RCTJSErrorFromNSError(error)]);
return;
}
Expand Down Expand Up @@ -365,7 +391,7 @@ - (void)fitness_getFlightsClimbedOnDay:(NSDictionary *)input callback:(RCTRespon
HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierFlightsClimbed];

[self fetchSumOfSamplesOnDayForType:quantityType unit:unit includeManuallyAdded:includeManuallyAdded day:date completion:^(double count, NSDate *startDate, NSDate *endDate, NSError *error) {
if (!count && count != 0) {
if ((!count && count != 0) || error != nil) {
callback(@[RCTJSErrorFromNSError(error)]);
return;
}
Expand Down
7 changes: 6 additions & 1 deletion RCTAppleHealthKit/RCTAppleHealthKit+Methods_Results.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@

- (void)results_getBloodGlucoseSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)results_getCarbohydratesSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)results_getInsulinDeliverySamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)results_saveBloodGlucoseSample:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)results_saveCarbohydratesSample:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;

- (void)results_deleteBloodGlucoseSample:(NSString *)oid callback:(RCTResponseSenderBlock)callback;
- (void)results_deleteCarbohydratesSample:(NSString *)oid callback:(RCTResponseSenderBlock)callback;
- (void)results_saveInsulinDeliverySample:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)results_deleteInsulinDeliverySample:(NSString *)oid callback:(RCTResponseSenderBlock)callback;
- (void)results_registerObservers:(RCTBridge *)bridge hasListeners:(bool)hasListeners;

@end
Loading

0 comments on commit 7ce15ab

Please sign in to comment.