From 7be576f73c6b27fdf4b512dbbf906cc0e2009185 Mon Sep 17 00:00:00 2001 From: Rodolfo Campos Date: Thu, 13 Jan 2022 17:14:35 -0400 Subject: [PATCH 1/2] Add conversion for count/min (e.g. HeartRate) samples --- RCTAppleHealthKit/RCTAppleHealthKit+Queries.m | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m index db32fb89..49129b63 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m @@ -190,7 +190,17 @@ - (void)fetchSamplesOfType:(HKSampleType *)type for (HKQuantitySample *sample in results) { @try { HKQuantity *quantity = sample.quantity; - double value = [quantity doubleValueForUnit:unit]; + double value = 0; + @try { + value = [quantity doubleValueForUnit:unit]; + } @catch (NSException *exception) { + if (unit != [HKUnit countUnit]) { + @throw exception; + } + // Retry only needed for count/min units, e.g. HeartRate + NSLog(@"Trying to extract quantity again in case the unit is count/min"); + value = [quantity doubleValueForUnit:[ HKUnit unitFromString: kCountPerMinUnitStr ]]; + } NSString * valueType = @"quantity"; if (unit == [HKUnit mileUnit]) { From 3c2142bce735172f2f4d516d17f9ab856b6d9151 Mon Sep 17 00:00:00 2001 From: Rodolfo Campos Date: Thu, 13 Jan 2022 17:16:11 -0400 Subject: [PATCH 2/2] Add count/min unit constant --- RCTAppleHealthKit/RCTAppleHealthKit+Queries.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m index 49129b63..048b939d 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m @@ -13,6 +13,8 @@ #import #import +#define kCountPerMinUnitStr @"count/min" + @implementation RCTAppleHealthKit (Queries) - (void)fetchMostRecentQuantitySampleOfType:(HKQuantityType *)quantityType