Commit 7c741d25 authored by Greg Wilson's avatar Greg Wilson

added fitness_getStepCountForDay method

parent f3f15d4b
......@@ -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
......@@ -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
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