Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented new function to get the flights climbed in a defined star… #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
- (void)fitness_getDailyDistanceCyclingSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_getFlightsClimbedOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_getDailyFlightsClimbedSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_getFlightsClimbedBetweenDates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;

@end
92 changes: 64 additions & 28 deletions RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ - (void)fitness_getSamples:(NSDictionary *)input callback:(RCTResponseSenderBloc
NSString *type = [RCTAppleHealthKit stringFromOptions:input key:@"type" withDefault:@"Walking"];
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:[NSDate date]];
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];

NSPredicate *predicate = [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionStrictStartDate];

HKSampleType *samplesType = [RCTAppleHealthKit hkQuantityTypeFromString:type];
if ([type isEqual:@"Running"] || [type isEqual:@"Cycling"]) {
unit = [HKUnit mileUnit];
Expand All @@ -85,12 +85,12 @@ - (void)fitness_setObserver:(NSDictionary *)input
{
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit countUnit]];
NSString *type = [RCTAppleHealthKit stringFromOptions:input key:@"type" withDefault:@"Walking"];

HKSampleType *samplesType = [RCTAppleHealthKit hkQuantityTypeFromString:type];
if ([type isEqual:@"Running"] || [type isEqual:@"Cycling"]) {
unit = [HKUnit mileUnit];
}

[self setObserverForType:samplesType unit:unit];
}

Expand All @@ -102,9 +102,9 @@ - (void)fitness_getDailyStepSamples:(NSDictionary *)input callback:(RCTResponseS
BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false];
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil];
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
NSUInteger period = [RCTAppleHealthKit uintFromOptions:input key:@"period" withDefault:60];
NSUInteger period = [RCTAppleHealthKit uintFromOptions:input key:@"period" withDefault:60];
BOOL includeManuallyAdded = [RCTAppleHealthKit boolFromOptions:input key:@"includeManuallyAdded" withDefault:false];

if(startDate == nil){
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
return;
Expand Down Expand Up @@ -174,8 +174,8 @@ - (void)fitness_initializeStepEventObserver:(NSDictionary *)input callback:(RCTR
return;
}

[self.bridge.eventDispatcher sendAppEventWithName:@"change:steps"
body:@{@"name": @"change:steps"}];
[self.bridge.eventDispatcher sendAppEventWithName:@"change:steps"
body:@{@"name": @"change:steps"}];

// If you have subscribed for background updates you must call the completion handler here.
// completionHandler();
Expand All @@ -200,10 +200,10 @@ - (void)fitness_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(R
}

NSDictionary *response = @{
@"value" : @(distance),
@"startDate" : [RCTAppleHealthKit buildISO8601StringFromDate:startDate],
@"endDate" : [RCTAppleHealthKit buildISO8601StringFromDate:endDate],
};
@"value" : @(distance),
@"startDate" : [RCTAppleHealthKit buildISO8601StringFromDate:startDate],
@"endDate" : [RCTAppleHealthKit buildISO8601StringFromDate:endDate],
};


callback(@[[NSNull null], response]);
Expand All @@ -223,9 +223,9 @@ - (void)fitness_getDailyDistanceWalkingRunningSamples:(NSDictionary *)input call
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
return;
}

HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning];

[self fetchCumulativeSumStatisticsCollection:quantityType
unit:unit
period:period
Expand Down Expand Up @@ -257,9 +257,9 @@ - (void)fitness_getDailyDistanceSwimmingSamples:(NSDictionary *)input callback:(
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
return;
}

HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceSwimming];

[self fetchCumulativeSumStatisticsCollection:quantityType
unit:unit
period:period
Expand Down Expand Up @@ -291,10 +291,10 @@ - (void)fitness_getDistanceCyclingOnDay:(NSDictionary *)input callback:(RCTRespo
}

NSDictionary *response = @{
@"value" : @(distance),
@"startDate" : [RCTAppleHealthKit buildISO8601StringFromDate:startDate],
@"endDate" : [RCTAppleHealthKit buildISO8601StringFromDate:endDate],
};
@"value" : @(distance),
@"startDate" : [RCTAppleHealthKit buildISO8601StringFromDate:startDate],
@"endDate" : [RCTAppleHealthKit buildISO8601StringFromDate:endDate],
};

callback(@[[NSNull null], response]);
}];
Expand All @@ -313,9 +313,9 @@ - (void)fitness_getDailyDistanceCyclingSamples:(NSDictionary *)input callback:(R
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
return;
}

HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceCycling];

[self fetchCumulativeSumStatisticsCollection:quantityType
unit:unit
period:period
Expand Down Expand Up @@ -347,10 +347,10 @@ - (void)fitness_getFlightsClimbedOnDay:(NSDictionary *)input callback:(RCTRespon
}

NSDictionary *response = @{
@"value" : @(count),
@"startDate" : [RCTAppleHealthKit buildISO8601StringFromDate:startDate],
@"endDate" : [RCTAppleHealthKit buildISO8601StringFromDate:endDate],
};
@"value" : @(count),
@"startDate" : [RCTAppleHealthKit buildISO8601StringFromDate:startDate],
@"endDate" : [RCTAppleHealthKit buildISO8601StringFromDate:endDate],
};

callback(@[[NSNull null], response]);
}];
Expand All @@ -367,9 +367,9 @@ - (void)fitness_getDailyFlightsClimbedSamples:(NSDictionary *)input callback:(RC
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
return;
}

HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierFlightsClimbed];

[self fetchCumulativeSumStatisticsCollection:quantityType
unit:unit
startDate:startDate
Expand All @@ -385,4 +385,40 @@ - (void)fitness_getDailyFlightsClimbedSamples:(NSDictionary *)input callback:(RC
}];
}

- (void)fitness_getFlightsClimbedBetweenDates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKUnit *unit = [HKUnit countUnit];
NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit];
BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false];
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil];
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
NSUInteger intervalDay = [RCTAppleHealthKit uintFromOptions:input key:@"intervalDay" withDefault:1];
NSUInteger intervalHour = [RCTAppleHealthKit uintFromOptions:input key:@"intervalHour" withDefault:0];
NSUInteger intervalMinute = [RCTAppleHealthKit uintFromOptions:input key:@"intervalMinute" withDefault:0];
if(startDate == nil){
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
return;
}

HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierFlightsClimbed];

[self fetchCumulativeSumStatisticsCollection:quantityType
unit:unit
startDate:startDate
endDate:endDate
ascending:ascending
limit:limit
intervalDay:intervalDay
intervalHour:intervalHour
intervalMinute:intervalMinute
completion:^(NSArray *arr, NSError *err) {
if (err != nil) {
NSLog(@"error with fetchCumulativeSumStatisticsCollection: %@", err);
callback(@[RCTMakeError(@"error with fetchCumulativeSumStatisticsCollection", err, nil)]);
return;
}
callback(@[[NSNull null], arr]);
}];
}

@end
14 changes: 13 additions & 1 deletion RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
ascending:(BOOL)asc
limit:(NSUInteger)lim
completion:(void (^)(NSArray *, NSError *))completion;

- (void)fetchCumulativeSumStatisticsCollection:(HKQuantityType *)quantityType
unit:(HKUnit *)unit
startDate:(NSDate *)startDate
endDate:(NSDate *)endDate
ascending:(BOOL)asc
limit:(NSUInteger)lim
intervalDay:(NSUInteger)intervalDay
intervalHour:(NSUInteger)intervalHour
intervalMinute:(NSUInteger)intervalMinute
completion:(void (^)(NSArray *, NSError *))completionHandler;

- (void)fetchCumulativeSumStatisticsCollection:(HKQuantityType *)quantityType
unit:(HKUnit *)unit
startDate:(NSDate *)startDate
Expand All @@ -62,7 +74,7 @@


- (void)fetchSleepCategorySamplesForPredicate:(NSPredicate *)predicate
limit:(NSUInteger)lim
limit:(NSUInteger)lim
completion:(void (^)(NSArray *, NSError *))completion;

@end
Loading