// // RCTAppleHealthKit+Methods_Activity.m // RCTAppleHealthKit // // Created by Alexander Vallorosi on 4/27/17. // Copyright © 2017 Alexander Vallorosi. All rights reserved. // #import "RCTAppleHealthKit+Methods_Activity.h" #import "RCTAppleHealthKit+Queries.h" #import "RCTAppleHealthKit+Utils.h" @implementation RCTAppleHealthKit (Methods_Activity) - (void)activity_getActiveEnergyBurned:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { HKQuantityType *activeEnergyType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierActiveEnergyBurned]; NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil]; NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]]; HKUnit *cal = [HKUnit kilocalorieUnit]; if(startDate == nil){ callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]); return; } NSPredicate * predicate = [RCTAppleHealthKit predicateForSamplesBetweenDates:startDate endDate:endDate]; [self fetchQuantitySamplesOfType:activeEnergyType unit:cal predicate:predicate ascending:false limit:HKObjectQueryNoLimit completion:^(NSArray *results, NSError *error) { if(results){ callback(@[[NSNull null], results]); return; } else { NSLog(@"error getting active energy burned samples: %@", error); callback(@[RCTMakeError(@"error getting active energy burned samples", nil, nil)]); return; } }]; } @end