diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h index 150f2745aaa8e2c520c7e72d3825a189121d9498..8f5fdd8eef34f0a57fc50faaa0b314d092a990d4 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h @@ -11,5 +11,6 @@ @interface RCTAppleHealthKit (Methods_Fitness) - (void)fitness_getStepCountForToday:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)fitness_getStepCountForDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m index 31ac748ce524b6430b2d45a2238391f72f80e2dd..abd99385b8ac40f6d15f493a238a688412783523 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m @@ -8,6 +8,7 @@ #import "RCTAppleHealthKit+Methods_Fitness.h" #import "RCTAppleHealthKit+Queries.h" +#import "RCTAppleHealthKit+Utils.h" @implementation RCTAppleHealthKit (Methods_Fitness) @@ -27,4 +28,27 @@ }]; } + +- (void)fitness_getStepCountForDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback +{ + NSDate *date = [RCTAppleHealthKit dateFromOptions:input]; + if(date == nil) { + callback(@[RCTMakeError(@"could not parse date from options.date", nil, nil)]); + return; + } + + HKQuantityType *stepCountType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; + HKUnit *stepsUnit = [HKUnit countUnit]; + + [self fetchSumOfSamplesOnDayForType:stepCountType unit:stepsUnit day:date completion:^(double totalSteps, NSError *error) { + if (!totalSteps) { + NSLog(@"could not fetch step count for day: %@", error); + callback(@[RCTMakeError(@"could not fetch step count for day", error, nil)]); + return; + } + callback(@[[NSNull null], @(totalSteps)]); + }]; +} + + @end