From fd433d53f568a4215fdb9175d6f94d9ca3ba5847 Mon Sep 17 00:00:00 2001 From: Evgenii Evstropov Date: Sun, 4 Feb 2018 00:44:26 +0100 Subject: [PATCH] support multiple types of retrieving samples (just names confusing) --- .../RCTAppleHealthKit+Methods_Fitness.m | 17 ++++++++++++++--- RCTAppleHealthKit/RCTAppleHealthKit+Queries.m | 1 - 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m index 9decba1..09994bd 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m @@ -54,6 +54,7 @@ NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit]; BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false]; BOOL isTracked = [RCTAppleHealthKit boolFromOptions:input key:@"isTracked" withDefault:true]; + NSString *type = [RCTAppleHealthKit stringFromOptions:input key:@"type" withDefault:@"Walking"]; NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil]; NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]]; if(startDate == nil){ @@ -62,7 +63,6 @@ } NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"YYYY-MM-dd-hh-mm-ss"]; - NSLog(@"samples interval: %@ %@",[formatter stringFromDate:startDate], [formatter stringFromDate:endDate]); // no isTracked NSArray *subPredicates = [[NSArray alloc] init]; @@ -74,11 +74,22 @@ subPredicates = [subPredicatesAux copy]; NSPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:subPredicates]; - HKQuantityType *stepCountType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; + HKQuantityType *samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; + if ([type isEqual:@"Walking"]) { + samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; + } else if ([type isEqual:@"StairClimbing"]) { + samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierFlightsClimbed]; + } else if ([type isEqual:@"Running"]){ + samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning]; + unit = [HKUnit mileUnit]; + } else if ([type isEqual:@"Cycling"]){ + samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceCycling]; + unit = [HKUnit mileUnit]; + } NSString * paramName = @"isTracked"; - [self fetchQuantitySamplesOfType:stepCountType + [self fetchQuantitySamplesOfType:samplesType unit:unit predicate:predicate ascending:ascending diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m index fab08e2..a0c0486 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m @@ -113,7 +113,6 @@ additionalParamName:(NSString *)paramName additionalParam:(BOOL)param completion:(void (^)(NSArray *, NSError *))completion { - NSSortDescriptor *timeSortDescriptor = [[NSSortDescriptor alloc] initWithKey:HKSampleSortIdentifierEndDate ascending:asc]; -- 2.26.2