Commit fd433d53 authored by Evgenii Evstropov's avatar Evgenii Evstropov

support multiple types of retrieving samples (just names confusing)

parent dda3ea95
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit]; NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit];
BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false]; BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false];
BOOL isTracked = [RCTAppleHealthKit boolFromOptions:input key:@"isTracked" withDefault:true]; 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 *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil];
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]]; NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
if(startDate == nil){ if(startDate == nil){
...@@ -62,7 +63,6 @@ ...@@ -62,7 +63,6 @@
} }
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"YYYY-MM-dd-hh-mm-ss"]; [formatter setDateFormat:@"YYYY-MM-dd-hh-mm-ss"];
NSLog(@"samples interval: %@ %@",[formatter stringFromDate:startDate], [formatter stringFromDate:endDate]);
// no isTracked // no isTracked
NSArray *subPredicates = [[NSArray alloc] init]; NSArray *subPredicates = [[NSArray alloc] init];
...@@ -74,11 +74,22 @@ ...@@ -74,11 +74,22 @@
subPredicates = [subPredicatesAux copy]; subPredicates = [subPredicatesAux copy];
NSPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:subPredicates]; 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"; NSString * paramName = @"isTracked";
[self fetchQuantitySamplesOfType:stepCountType [self fetchQuantitySamplesOfType:samplesType
unit:unit unit:unit
predicate:predicate predicate:predicate
ascending:ascending ascending:ascending
......
...@@ -113,7 +113,6 @@ ...@@ -113,7 +113,6 @@
additionalParamName:(NSString *)paramName additionalParamName:(NSString *)paramName
additionalParam:(BOOL)param additionalParam:(BOOL)param
completion:(void (^)(NSArray *, NSError *))completion { completion:(void (^)(NSArray *, NSError *))completion {
NSSortDescriptor *timeSortDescriptor = [[NSSortDescriptor alloc] initWithKey:HKSampleSortIdentifierEndDate NSSortDescriptor *timeSortDescriptor = [[NSSortDescriptor alloc] initWithKey:HKSampleSortIdentifierEndDate
ascending:asc]; ascending:asc];
......
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