diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h index 8f5fdd8eef34f0a57fc50faaa0b314d092a990d4..e6fce0565f4e507a198946d0eee7e228ca0e82ef 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h @@ -13,4 +13,6 @@ - (void)fitness_getStepCountForToday:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)fitness_getStepCountForDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)fitness_getDailyStepCounts:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m index abd99385b8ac40f6d15f493a238a688412783523..4769a73b0622b3c362e43ca7f8588b79af786b9e 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m @@ -51,4 +51,31 @@ } + + +- (void)fitness_getDailyStepCounts:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback +{ + NSDate *startDate = [RCTAppleHealthKit startDateFromOptions:input]; + NSDate *endDate = [RCTAppleHealthKit endDateFromOptionsDefaultNow:input]; + + if(startDate == nil) { + callback(@[RCTMakeError(@"could not parse required startDate from options.startDate", nil, nil)]); + return; + } + + HKQuantityType *stepCountType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; + HKUnit *stepsUnit = [HKUnit countUnit]; + + [self fetchCumulativeSumStatisticsCollection:stepCountType unit:stepsUnit startDate:startDate endDate:endDate completion:^(NSArray *arr, NSError *err){ + if (err != nil) { + NSLog(@"error with fetchCumulativeSumStatisticsCollection: %@", err); + callback(@[RCTMakeError(@"error with fetchCumulativeSumStatisticsCollection", err, nil)]); + return; + } + callback(@[[NSNull null], arr]); + }]; +} + + + @end