Commit f3f15d4b authored by Greg Wilson's avatar Greg Wilson

added fetchSumOfSamplesOnDayForType method to Queries

parent d32e49c9
......@@ -12,5 +12,6 @@
- (void)fetchMostRecentQuantitySampleOfType:(HKQuantityType *)quantityType predicate:(NSPredicate *)predicate completion:(void (^)(HKQuantity *mostRecentQuantity, NSDate *startDate, NSDate *endDate, NSError *error))completion;
- (void)fetchSumOfSamplesTodayForType:(HKQuantityType *)quantityType unit:(HKUnit *)unit completion:(void (^)(double, NSError *))completionHandler;
- (void)fetchSumOfSamplesOnDayForType:(HKQuantityType *)quantityType unit:(HKUnit *)unit day:(NSDate *)day completion:(void (^)(double, NSError *))completionHandler;
@end
......@@ -59,4 +59,26 @@
[self.healthStore executeQuery:query];
}
- (void)fetchSumOfSamplesOnDayForType:(HKQuantityType *)quantityType unit:(HKUnit *)unit day:(NSDate *)day completion:(void (^)(double, NSError *))completionHandler {
NSPredicate *predicate = [RCTAppleHealthKit predicateForSamplesOnDay:day];
HKStatisticsQuery *query = [[HKStatisticsQuery alloc] initWithQuantityType:quantityType
quantitySamplePredicate:predicate
options:HKStatisticsOptionCumulativeSum
completionHandler:^(HKStatisticsQuery *query, HKStatistics *result, NSError *error) {
HKQuantity *sum = [result sumQuantity];
if (completionHandler) {
double value = [sum doubleValueForUnit:unit];
completionHandler(value, error);
}
}];
[self.healthStore executeQuery:query];
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment