Skip to content

Commit

Permalink
- Fixed a crash when trying to fetch statistical data with no user pe…
Browse files Browse the repository at this point in the history
…rmission
  • Loading branch information
GGGava committed Jan 19, 2023
1 parent 195e3e4 commit ff09ea8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 5 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 @@ -218,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 @@ -277,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 @@ -334,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 @@ -391,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
6 changes: 6 additions & 0 deletions RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,12 @@ - (void)fetchSumOfSamplesOnDayForType:(HKQuantityType *)quantityType
NSDate *startDate = result.startDate;
NSDate *endDate = result.endDate;
double value = [sum doubleValueForUnit:unit];
if (startDate == nil || endDate == nil) {
error = [[NSError alloc] initWithDomain:@"AppleHealthKit"
code:0
userInfo:@{@"Error reason": @"Could not fetch statistics: Not authorized"}
];
}
completionHandler(value, startDate, endDate, error);
}
}];
Expand Down

0 comments on commit ff09ea8

Please sign in to comment.