Commit dda3ea95 authored by EEvgeniiF's avatar EEvgeniiF

isTracked step samples

parent 15e89ceb
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // Created by Greg Wilson on 2016-06-26.
// This source code is licensed under the MIT-style license found in the // Copyright © 2016 Greg Wilson. All rights reserved.
// LICENSE file in the root directory of this source tree.
// //
#import "RCTAppleHealthKit.h" #import "RCTAppleHealthKit.h"
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // Created by Greg Wilson on 2016-06-26.
// This source code is licensed under the MIT-style license found in the // Copyright © 2016 Greg Wilson. All rights reserved.
// LICENSE file in the root directory of this source tree.
// //
#import "RCTAppleHealthKit+Methods_Body.h" #import "RCTAppleHealthKit+Methods_Body.h"
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-29. // Created by Greg Wilson on 2016-06-29.
// This source code is licensed under the MIT-style license found in the // Copyright © 2016 Greg Wilson. All rights reserved.
// LICENSE file in the root directory of this source tree.
// //
#import "RCTAppleHealthKit.h" #import "RCTAppleHealthKit.h"
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-29. // Created by Greg Wilson on 2016-06-29.
// This source code is licensed under the MIT-style license found in the // Copyright © 2016 Greg Wilson. All rights reserved.
// LICENSE file in the root directory of this source tree.
// //
#import "RCTAppleHealthKit+Methods_Characteristic.h" #import "RCTAppleHealthKit+Methods_Characteristic.h"
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // Created by Greg Wilson on 2016-06-26.
// This source code is licensed under the MIT-style license found in the // Copyright © 2016 Greg Wilson. All rights reserved.
// LICENSE file in the root directory of this source tree.
// //
#import "RCTAppleHealthKit.h" #import "RCTAppleHealthKit.h"
...@@ -12,6 +11,7 @@ ...@@ -12,6 +11,7 @@
@interface RCTAppleHealthKit (Methods_Fitness) @interface RCTAppleHealthKit (Methods_Fitness)
- (void)fitness_getStepCountOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)fitness_getStepCountOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_getStepCountSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_getDailyStepSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)fitness_getDailyStepSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_saveSteps:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)fitness_saveSteps:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_initializeStepEventObserver:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)fitness_initializeStepEventObserver:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // Created by Greg Wilson on 2016-06-26.
// This source code is licensed under the MIT-style license found in the // Copyright © 2016 Greg Wilson. All rights reserved.
// LICENSE file in the root directory of this source tree.
// //
#import "RCTAppleHealthKit+Methods_Fitness.h" #import "RCTAppleHealthKit+Methods_Fitness.h"
...@@ -49,6 +48,55 @@ ...@@ -49,6 +48,55 @@
}]; }];
} }
- (void)fitness_getStepCountSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit countUnit]];
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];
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil];
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
if(startDate == nil){
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
return;
}
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];
NSMutableArray *subPredicatesAux = [[NSMutableArray alloc] init];
NSPredicate *predicateDate = [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionStrictStartDate];
NSPredicate *predicateType = isTracked ? [NSPredicate predicateWithFormat:@"metadata.%K != YES", HKMetadataKeyWasUserEntered] : [NSPredicate predicateWithFormat:@"metadata.%K == YES", HKMetadataKeyWasUserEntered];
[subPredicatesAux addObject:predicateDate];
[subPredicatesAux addObject:predicateType];
subPredicates = [subPredicatesAux copy];
NSPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:subPredicates];
HKQuantityType *stepCountType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
NSString * paramName = @"isTracked";
[self fetchQuantitySamplesOfType:stepCountType
unit:unit
predicate:predicate
ascending:ascending
limit:limit
additionalParamName:paramName
additionalParam:isTracked
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;
}
}];
}
- (void)fitness_getDailyStepSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)fitness_getDailyStepSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-11-06. // Created by Greg Wilson on 2016-11-06.
// This source code is licensed under the MIT-style license found in the // Copyright © 2016 Greg Wilson. All rights reserved.
// LICENSE file in the root directory of this source tree.
// //
#import "RCTAppleHealthKit.h" #import "RCTAppleHealthKit.h"
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-11-06. // Created by Greg Wilson on 2016-11-06.
// This source code is licensed under the MIT-style license found in the // Copyright © 2016 Greg Wilson. All rights reserved.
// LICENSE file in the root directory of this source tree.
// //
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // Created by Greg Wilson on 2016-06-26.
// This source code is licensed under the MIT-style license found in the // Copyright © 2016 Greg Wilson. All rights reserved.
// LICENSE file in the root directory of this source tree.
// //
#import "RCTAppleHealthKit.h" #import "RCTAppleHealthKit.h"
...@@ -25,6 +24,14 @@ ...@@ -25,6 +24,14 @@
ascending:(BOOL)asc ascending:(BOOL)asc
limit:(NSUInteger)lim limit:(NSUInteger)lim
completion:(void (^)(NSArray *, NSError *))completion; completion:(void (^)(NSArray *, NSError *))completion;
- (void)fetchQuantitySamplesOfType:(HKQuantityType *)quantityType
unit:(HKUnit *)unit
predicate:(NSPredicate *)predicate
ascending:(BOOL)asc
limit:(NSUInteger)lim
additionalParamName:(NSString *)paramName
additionalParam:(BOOL)param
completion:(void (^)(NSArray *, NSError *))completion;
- (void)fetchCorrelationSamplesOfType:(HKQuantityType *)quantityType - (void)fetchCorrelationSamplesOfType:(HKQuantityType *)quantityType
unit:(HKUnit *)unit unit:(HKUnit *)unit
predicate:(NSPredicate *)predicate predicate:(NSPredicate *)predicate
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // Created by Greg Wilson on 2016-06-26.
// This source code is licensed under the MIT-style license found in the // Copyright © 2016 Greg Wilson. All rights reserved.
// LICENSE file in the root directory of this source tree.
// //
#import "RCTAppleHealthKit+Queries.h" #import "RCTAppleHealthKit+Queries.h"
...@@ -106,7 +105,64 @@ ...@@ -106,7 +105,64 @@
[self.healthStore executeQuery:query]; [self.healthStore executeQuery:query];
} }
- (void)fetchQuantitySamplesOfType:(HKQuantityType *)quantityType
unit:(HKUnit *)unit
predicate:(NSPredicate *)predicate
ascending:(BOOL)asc
limit:(NSUInteger)lim
additionalParamName:(NSString *)paramName
additionalParam:(BOOL)param
completion:(void (^)(NSArray *, NSError *))completion {
NSSortDescriptor *timeSortDescriptor = [[NSSortDescriptor alloc] initWithKey:HKSampleSortIdentifierEndDate
ascending:asc];
// declare the block
void (^handlerBlock)(HKSampleQuery *query, NSArray *results, NSError *error);
// create and assign the block
handlerBlock = ^(HKSampleQuery *query, NSArray *results, NSError *error) {
if (!results) {
if (completion) {
completion(nil, error);
}
return;
}
if (completion) {
NSMutableArray *data = [NSMutableArray arrayWithCapacity:1];
dispatch_async(dispatch_get_main_queue(), ^{
for (HKQuantitySample *sample in results) {
HKQuantity *quantity = sample.quantity;
double value = [quantity doubleValueForUnit:unit];
NSString *startDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.startDate];
NSString *endDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.endDate];
NSDictionary *elem = @{
@"value" : @(value),
@"startDate" : startDateString,
@"endDate" : endDateString,
paramName : @(param),
};
[data addObject:elem];
}
completion(data, error);
});
}
};
HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:quantityType
predicate:predicate
limit:lim
sortDescriptors:@[timeSortDescriptor]
resultsHandler:handlerBlock];
[self.healthStore executeQuery:query];
}
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // Created by Greg Wilson on 2016-06-26.
// This source code is licensed under the MIT-style license found in the // Copyright © 2016 Greg Wilson. All rights reserved.
// LICENSE file in the root directory of this source tree.
// //
#import "RCTAppleHealthKit.h" #import "RCTAppleHealthKit.h"
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // Created by Greg Wilson on 2016-06-26.
// This source code is licensed under the MIT-style license found in the // Copyright © 2016 Greg Wilson. All rights reserved.
// LICENSE file in the root directory of this source tree.
// //
#import "RCTAppleHealthKit+TypesAndPermissions.h" #import "RCTAppleHealthKit+TypesAndPermissions.h"
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // Created by Greg Wilson on 2016-06-26.
// This source code is licensed under the MIT-style license found in the // Copyright © 2016 Greg Wilson. All rights reserved.
// LICENSE file in the root directory of this source tree.
// //
#import "RCTAppleHealthKit.h" #import "RCTAppleHealthKit.h"
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // Created by Greg Wilson on 2016-06-26.
// This source code is licensed under the MIT-style license found in the // Copyright © 2016 Greg Wilson. All rights reserved.
// LICENSE file in the root directory of this source tree.
// //
#import "RCTAppleHealthKit+Utils.h" #import "RCTAppleHealthKit+Utils.h"
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // Created by Greg Wilson on 2016-06-26.
// This source code is licensed under the MIT-style license found in the // Copyright © 2016 Greg Wilson. All rights reserved.
// LICENSE file in the root directory of this source tree.
// //
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// RCTAppleHealthKit // RCTAppleHealthKit
// //
// Created by Greg Wilson on 2016-06-26. // Created by Greg Wilson on 2016-06-26.
// This source code is licensed under the MIT-style license found in the // Copyright © 2016 Greg Wilson. All rights reserved.
// LICENSE file in the root directory of this source tree.
// //
#import "RCTAppleHealthKit.h" #import "RCTAppleHealthKit.h"
...@@ -107,6 +106,11 @@ RCT_EXPORT_METHOD(getStepCount:(NSDictionary *)input callback:(RCTResponseSender ...@@ -107,6 +106,11 @@ RCT_EXPORT_METHOD(getStepCount:(NSDictionary *)input callback:(RCTResponseSender
[self fitness_getStepCountOnDay:input callback:callback]; [self fitness_getStepCountOnDay:input callback:callback];
} }
RCT_EXPORT_METHOD(getStepCountSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self fitness_getStepCountSamples:input callback:callback];
}
RCT_EXPORT_METHOD(getDailyStepCountSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) RCT_EXPORT_METHOD(getDailyStepCountSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{ {
[self fitness_getDailyStepSamples:input callback:callback]; [self fitness_getDailyStepSamples:input callback:callback];
......
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