Commit ddc8b04c authored by Greg Wilson's avatar Greg Wilson

some clean up

parent 7fd6c500
...@@ -24,5 +24,4 @@ ...@@ -24,5 +24,4 @@
- (void)body_getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)body_getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getLatestLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)body_getLatestLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
@end @end
...@@ -10,13 +10,11 @@ ...@@ -10,13 +10,11 @@
#import "RCTAppleHealthKit+Queries.h" #import "RCTAppleHealthKit+Queries.h"
#import "RCTAppleHealthKit+Utils.h" #import "RCTAppleHealthKit+Utils.h"
@implementation RCTAppleHealthKit (Methods_Body) @implementation RCTAppleHealthKit (Methods_Body)
- (void)body_getLatestWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)body_getLatestWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
// Query to get the user's latest weight, if it exists.
HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass]; HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass];
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input]; HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input];
...@@ -80,8 +78,6 @@ ...@@ -80,8 +78,6 @@
} }
- (void)body_saveWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)body_saveWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
double weight = [RCTAppleHealthKit doubleValueFromOptions:input]; double weight = [RCTAppleHealthKit doubleValueFromOptions:input];
...@@ -105,7 +101,6 @@ ...@@ -105,7 +101,6 @@
- (void)body_getLatestBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)body_getLatestBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
// Query to get the user's latest BMI, if it exists.
HKQuantityType *bmiType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMassIndex]; HKQuantityType *bmiType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMassIndex];
[self fetchMostRecentQuantitySampleOfType:bmiType [self fetchMostRecentQuantitySampleOfType:bmiType
...@@ -132,7 +127,6 @@ ...@@ -132,7 +127,6 @@
} }
- (void)body_saveBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)body_saveBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
double bmi = [RCTAppleHealthKit doubleValueFromOptions:input]; double bmi = [RCTAppleHealthKit doubleValueFromOptions:input];
...@@ -154,7 +148,6 @@ ...@@ -154,7 +148,6 @@
} }
- (void)body_getLatestHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)body_getLatestHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
HKQuantityType *heightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight]; HKQuantityType *heightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight];
...@@ -187,7 +180,6 @@ ...@@ -187,7 +180,6 @@
} }
- (void)body_getHeightSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)body_getHeightSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
HKQuantityType *heightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight]; HKQuantityType *heightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight];
...@@ -221,7 +213,6 @@ ...@@ -221,7 +213,6 @@
} }
- (void)body_saveHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)body_saveHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
double height = [RCTAppleHealthKit doubleValueFromOptions:input]; double height = [RCTAppleHealthKit doubleValueFromOptions:input];
...@@ -247,7 +238,6 @@ ...@@ -247,7 +238,6 @@
} }
- (void)body_getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)body_getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
HKQuantityType *bodyFatPercentType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyFatPercentage]; HKQuantityType *bodyFatPercentType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyFatPercentage];
...@@ -304,5 +294,4 @@ ...@@ -304,5 +294,4 @@
}]; }];
} }
@end @end
...@@ -78,6 +78,4 @@ ...@@ -78,6 +78,4 @@
callback(@[[NSNull null], response]); callback(@[[NSNull null], response]);
} }
@end @end
...@@ -10,19 +10,12 @@ ...@@ -10,19 +10,12 @@
@interface RCTAppleHealthKit (Methods_Fitness) @interface RCTAppleHealthKit (Methods_Fitness)
//- (void)fitness_getStepCountForToday:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_getStepCountOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)fitness_getStepCountOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
//- (void)fitness_getDailyStepCounts:(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;
- (void)fitness_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)fitness_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_getDistanceCyclingOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)fitness_getDistanceCyclingOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_getFlightsClimbedOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)fitness_getFlightsClimbedOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
@end @end
...@@ -16,25 +16,6 @@ ...@@ -16,25 +16,6 @@
@implementation RCTAppleHealthKit (Methods_Fitness) @implementation RCTAppleHealthKit (Methods_Fitness)
//- (void)fitness_getStepCountForToday:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
//{
// HKQuantityType *stepCountType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
// HKUnit *stepsUnit = [HKUnit countUnit];
//
// [self fetchSumOfSamplesTodayForType:stepCountType
// unit:stepsUnit
// completion:^(double totalSteps, NSError *error) {
// if (!totalSteps) {
// NSLog(@"Either an error occured fetching the user's step count information or none has been stored yet. In your app, try to handle this gracefully.");
// callback(@[RCTMakeError(@"Either an error occured fetching the user's step count information or none has been stored yet. In your app, try to handle this gracefully.", nil, nil)]);
// return;
// }
//
// callback(@[[NSNull null], @(totalSteps)]);
// }];
//}
- (void)fitness_getStepCountOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)fitness_getStepCountOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
NSDate *date = [RCTAppleHealthKit dateFromOptions:input key:@"date" withDefault:[NSDate date]]; NSDate *date = [RCTAppleHealthKit dateFromOptions:input key:@"date" withDefault:[NSDate date]];
...@@ -68,38 +49,6 @@ ...@@ -68,38 +49,6 @@
} }
//
//- (void)fitness_getDailyStepCounts:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
//{
// NSDate *startDate = [RCTAppleHealthKit startDateFromOptions:input];
// NSDate *endDate = [RCTAppleHealthKit endDateFromOptionsDefaultNow:input];
//
// if(startDate == nil) {
// callback(@[RCTMakeError(@"could not parse required startDate from options.startDate", nil, nil)]);
// return;
// }
//
// HKQuantityType *stepCountType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
// HKUnit *stepsUnit = [HKUnit countUnit];
//
// [self fetchCumulativeSumStatisticsCollection:stepCountType
// unit:stepsUnit
// startDate:startDate
// endDate:endDate
// 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]);
// }];
//}
- (void)fitness_getDailyStepSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)fitness_getDailyStepSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit countUnit]]; HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit countUnit]];
...@@ -131,7 +80,6 @@ ...@@ -131,7 +80,6 @@
} }
- (void)fitness_saveSteps:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)fitness_saveSteps:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
double value = [RCTAppleHealthKit doubleFromOptions:input key:@"value" withDefault:(double)0]; double value = [RCTAppleHealthKit doubleFromOptions:input key:@"value" withDefault:(double)0];
...@@ -159,7 +107,6 @@ ...@@ -159,7 +107,6 @@
} }
- (void)fitness_initializeStepEventObserver:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)fitness_initializeStepEventObserver:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
HKSampleType *sampleType = HKSampleType *sampleType =
...@@ -192,7 +139,6 @@ ...@@ -192,7 +139,6 @@
} }
- (void)fitness_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)fitness_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit meterUnit]]; HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit meterUnit]];
...@@ -268,8 +214,4 @@ ...@@ -268,8 +214,4 @@
}]; }];
} }
@end @end
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
@implementation RCTAppleHealthKit (Methods_Results) @implementation RCTAppleHealthKit (Methods_Results)
- (void)results_getBloodGlucoseSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)results_getBloodGlucoseSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
HKQuantityType *bloodGlucoseType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodGlucose]; HKQuantityType *bloodGlucoseType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodGlucose];
...@@ -38,5 +39,4 @@ ...@@ -38,5 +39,4 @@
}]; }];
} }
@end @end
...@@ -3,11 +3,8 @@ ...@@ -3,11 +3,8 @@
@interface RCTAppleHealthKit (Methods_Vitals) @interface RCTAppleHealthKit (Methods_Vitals)
- (void)vitals_getHeartRateSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)vitals_getHeartRateSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)vitals_getBodyTemperatureSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)vitals_getBodyTemperatureSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)vitals_getBloodPressureSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)vitals_getBloodPressureSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)vitals_getRespiratoryRateSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)vitals_getRespiratoryRateSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
@end @end
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
}]; }];
} }
- (void)vitals_getBodyTemperatureSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)vitals_getBodyTemperatureSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
HKQuantityType *bodyTemperatureType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyTemperature]; HKQuantityType *bodyTemperatureType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyTemperature];
...@@ -116,7 +117,6 @@ ...@@ -116,7 +117,6 @@
[data addObject:elem]; [data addObject:elem];
} }
callback(@[[NSNull null], data]); callback(@[[NSNull null], data]);
return; return;
} else { } else {
...@@ -127,6 +127,7 @@ ...@@ -127,6 +127,7 @@
}]; }];
} }
- (void)vitals_getRespiratoryRateSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)vitals_getRespiratoryRateSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
HKQuantityType *respiratoryRateType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierRespiratoryRate]; HKQuantityType *respiratoryRateType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierRespiratoryRate];
...@@ -162,5 +163,4 @@ ...@@ -162,5 +163,4 @@
}]; }];
} }
@end @end
...@@ -13,30 +13,23 @@ ...@@ -13,30 +13,23 @@
- (void)fetchMostRecentQuantitySampleOfType:(HKQuantityType *)quantityType predicate:(NSPredicate *)predicate completion:(void (^)(HKQuantity *mostRecentQuantity, NSDate *startDate, NSDate *endDate, NSError *error))completion; - (void)fetchMostRecentQuantitySampleOfType:(HKQuantityType *)quantityType predicate:(NSPredicate *)predicate completion:(void (^)(HKQuantity *mostRecentQuantity, NSDate *startDate, NSDate *endDate, NSError *error))completion;
- (void)fetchSumOfSamplesTodayForType:(HKQuantityType *)quantityType unit:(HKUnit *)unit completion:(void (^)(double, NSError *))completionHandler; - (void)fetchSumOfSamplesTodayForType:(HKQuantityType *)quantityType unit:(HKUnit *)unit completion:(void (^)(double, NSError *))completionHandler;
- (void)fetchSumOfSamplesOnDayForType:(HKQuantityType *)quantityType unit:(HKUnit *)unit day:(NSDate *)day completion:(void (^)(double, NSDate *, NSDate *, NSError *))completionHandler; - (void)fetchSumOfSamplesOnDayForType:(HKQuantityType *)quantityType unit:(HKUnit *)unit day:(NSDate *)day completion:(void (^)(double, NSDate *, NSDate *, NSError *))completionHandler;
- (void)fetchCumulativeSumStatisticsCollection:(HKQuantityType *)quantityType - (void)fetchCumulativeSumStatisticsCollection:(HKQuantityType *)quantityType
unit:(HKUnit *)unit unit:(HKUnit *)unit
startDate:(NSDate *)startDate startDate:(NSDate *)startDate
endDate:(NSDate *)endDate endDate:(NSDate *)endDate
completion:(void (^)(NSArray *, NSError *))completionHandler; completion:(void (^)(NSArray *, NSError *))completionHandler;
- (void)fetchQuantitySamplesOfType:(HKQuantityType *)quantityType - (void)fetchQuantitySamplesOfType:(HKQuantityType *)quantityType
unit:(HKUnit *)unit unit:(HKUnit *)unit
predicate:(NSPredicate *)predicate predicate:(NSPredicate *)predicate
ascending:(BOOL)asc ascending:(BOOL)asc
limit:(NSUInteger)lim limit:(NSUInteger)lim
completion:(void (^)(NSArray *, NSError *))completion; 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
ascending:(BOOL)asc ascending:(BOOL)asc
limit:(NSUInteger)lim limit:(NSUInteger)lim
completion:(void (^)(NSArray *, NSError *))completion; completion:(void (^)(NSArray *, NSError *))completion;
- (void)fetchCumulativeSumStatisticsCollection:(HKQuantityType *)quantityType - (void)fetchCumulativeSumStatisticsCollection:(HKQuantityType *)quantityType
unit:(HKUnit *)unit unit:(HKUnit *)unit
startDate:(NSDate *)startDate startDate:(NSDate *)startDate
...@@ -45,5 +38,4 @@ ...@@ -45,5 +38,4 @@
limit:(NSUInteger)lim limit:(NSUInteger)lim
completion:(void (^)(NSArray *, NSError *))completionHandler; completion:(void (^)(NSArray *, NSError *))completionHandler;
@end @end
...@@ -49,7 +49,6 @@ ...@@ -49,7 +49,6 @@
} }
- (void)fetchQuantitySamplesOfType:(HKQuantityType *)quantityType - (void)fetchQuantitySamplesOfType:(HKQuantityType *)quantityType
unit:(HKUnit *)unit unit:(HKUnit *)unit
predicate:(NSPredicate *)predicate predicate:(NSPredicate *)predicate
...@@ -97,7 +96,6 @@ ...@@ -97,7 +96,6 @@
} }
}; };
HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:quantityType HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:quantityType
predicate:predicate predicate:predicate
limit:lim limit:lim
...@@ -135,7 +133,6 @@ ...@@ -135,7 +133,6 @@
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
for (HKCorrelation *sample in results) { for (HKCorrelation *sample in results) {
NSString *startDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.startDate]; NSString *startDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.startDate];
NSString *endDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.endDate]; NSString *endDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.endDate];
...@@ -144,7 +141,6 @@ ...@@ -144,7 +141,6 @@
@"startDate" : startDateString, @"startDate" : startDateString,
@"endDate" : endDateString, @"endDate" : endDateString,
}; };
[data addObject:elem]; [data addObject:elem];
} }
...@@ -153,7 +149,6 @@ ...@@ -153,7 +149,6 @@
} }
}; };
HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:quantityType HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:quantityType
predicate:predicate predicate:predicate
limit:lim limit:lim
...@@ -164,10 +159,6 @@ ...@@ -164,10 +159,6 @@
} }
- (void)fetchSumOfSamplesTodayForType:(HKQuantityType *)quantityType - (void)fetchSumOfSamplesTodayForType:(HKQuantityType *)quantityType
unit:(HKUnit *)unit unit:(HKUnit *)unit
completion:(void (^)(double, NSError *))completionHandler { completion:(void (^)(double, NSError *))completionHandler {
...@@ -177,26 +168,17 @@ ...@@ -177,26 +168,17 @@
quantitySamplePredicate:predicate quantitySamplePredicate:predicate
options:HKStatisticsOptionCumulativeSum options:HKStatisticsOptionCumulativeSum
completionHandler:^(HKStatisticsQuery *query, HKStatistics *result, NSError *error) { completionHandler:^(HKStatisticsQuery *query, HKStatistics *result, NSError *error) {
HKQuantity *sum = [result sumQuantity]; HKQuantity *sum = [result sumQuantity];
if (completionHandler) { if (completionHandler) {
double value = [sum doubleValueForUnit:unit]; double value = [sum doubleValueForUnit:unit];
completionHandler(value, error); completionHandler(value, error);
} }
}]; }];
[self.healthStore executeQuery:query]; [self.healthStore executeQuery:query];
} }
- (void)fetchSumOfSamplesOnDayForType:(HKQuantityType *)quantityType - (void)fetchSumOfSamplesOnDayForType:(HKQuantityType *)quantityType
unit:(HKUnit *)unit unit:(HKUnit *)unit
day:(NSDate *)day day:(NSDate *)day
...@@ -207,7 +189,6 @@ ...@@ -207,7 +189,6 @@
quantitySamplePredicate:predicate quantitySamplePredicate:predicate
options:HKStatisticsOptionCumulativeSum options:HKStatisticsOptionCumulativeSum
completionHandler:^(HKStatisticsQuery *query, HKStatistics *result, NSError *error) { completionHandler:^(HKStatisticsQuery *query, HKStatistics *result, NSError *error) {
HKQuantity *sum = [result sumQuantity]; HKQuantity *sum = [result sumQuantity];
NSDate *startDate = result.startDate; NSDate *startDate = result.startDate;
NSDate *endDate = result.endDate; NSDate *endDate = result.endDate;
...@@ -215,20 +196,12 @@ ...@@ -215,20 +196,12 @@
double value = [sum doubleValueForUnit:unit]; double value = [sum doubleValueForUnit:unit];
completionHandler(value,startDate, endDate, error); completionHandler(value,startDate, endDate, error);
} }
}]; }];
[self.healthStore executeQuery:query]; [self.healthStore executeQuery:query];
} }
- (void)fetchCumulativeSumStatisticsCollection:(HKQuantityType *)quantityType - (void)fetchCumulativeSumStatisticsCollection:(HKQuantityType *)quantityType
unit:(HKUnit *)unit unit:(HKUnit *)unit
startDate:(NSDate *)startDate startDate:(NSDate *)startDate
...@@ -270,32 +243,18 @@ ...@@ -270,32 +243,18 @@
NSLog(@"%@: %f", date, value); NSLog(@"%@: %f", date, value);
NSString *dateString = [RCTAppleHealthKit buildISO8601StringFromDate:date]; NSString *dateString = [RCTAppleHealthKit buildISO8601StringFromDate:date];
NSArray *elem = @[dateString, @(value)]; NSArray *elem = @[dateString, @(value)];
[data addObject:elem]; [data addObject:elem];
} }
}]; }];
NSError *err; NSError *err;
completionHandler(data, err); completionHandler(data, err);
}; };
[self.healthStore executeQuery:query]; [self.healthStore executeQuery:query];
} }
- (void)fetchCumulativeSumStatisticsCollection:(HKQuantityType *)quantityType - (void)fetchCumulativeSumStatisticsCollection:(HKQuantityType *)quantityType
unit:(HKUnit *)unit unit:(HKUnit *)unit
startDate:(NSDate *)startDate startDate:(NSDate *)startDate
...@@ -347,10 +306,8 @@ ...@@ -347,10 +306,8 @@
@"startDate" : startDateString, @"startDate" : startDateString,
@"endDate" : endDateString, @"endDate" : endDateString,
}; };
[data addObject:elem]; [data addObject:elem];
} }
}]; }];
// is ascending by default // is ascending by default
if(asc == false) { if(asc == false) {
...@@ -370,16 +327,4 @@ ...@@ -370,16 +327,4 @@
[self.healthStore executeQuery:query]; [self.healthStore executeQuery:query];
} }
@end @end
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
@implementation RCTAppleHealthKit (TypesAndPermissions) @implementation RCTAppleHealthKit (TypesAndPermissions)
#pragma mark - HealthKit Permissions #pragma mark - HealthKit Permissions
- (NSDictionary *)readPermsDict { - (NSDictionary *)readPermsDict {
...@@ -48,6 +49,7 @@ ...@@ -48,6 +49,7 @@
return readPerms; return readPerms;
} }
- (NSDictionary *)writePermsDict { - (NSDictionary *)writePermsDict {
NSDictionary *writePerms = @{ NSDictionary *writePerms = @{
// Body Measurements // Body Measurements
...@@ -81,11 +83,9 @@ ...@@ -81,11 +83,9 @@
NSString *optionKey = options[i]; NSString *optionKey = options[i];
HKObjectType *val = [readPermDict objectForKey:optionKey]; HKObjectType *val = [readPermDict objectForKey:optionKey];
if(val != nil) { if(val != nil) {
// RCTLogInfo(@"Adding read permissions from options: %@", optionKey);
[readPermSet addObject:val]; [readPermSet addObject:val];
} }
} }
return readPermSet; return readPermSet;
} }
...@@ -99,11 +99,9 @@ ...@@ -99,11 +99,9 @@
NSString *optionKey = options[i]; NSString *optionKey = options[i];
HKObjectType *val = [writePermDict objectForKey:optionKey]; HKObjectType *val = [writePermDict objectForKey:optionKey];
if(val != nil) { if(val != nil) {
// RCTLogInfo(@"Adding write permissions from options: %@", optionKey);
[writePermSet addObject:val]; [writePermSet addObject:val];
} }
} }
return writePermSet; return writePermSet;
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
@implementation RCTAppleHealthKit (Utils) @implementation RCTAppleHealthKit (Utils)
#pragma mark - Utilities #pragma mark - Utilities
+ (NSDate *)parseISO8601DateFromString:(NSString *)date + (NSDate *)parseISO8601DateFromString:(NSString *)date
...@@ -17,31 +18,33 @@ ...@@ -17,31 +18,33 @@
NSDateFormatter *dateFormatter = [NSDateFormatter new]; NSDateFormatter *dateFormatter = [NSDateFormatter new];
NSLocale *posix = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]; NSLocale *posix = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
dateFormatter.locale = posix; dateFormatter.locale = posix;
// dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZZZZZ";
dateFormatter.dateFormat = @"yyyy'-'MM'-'dd'T'HH':'mm':'ss.SSSZ"; dateFormatter.dateFormat = @"yyyy'-'MM'-'dd'T'HH':'mm':'ss.SSSZ";
return [dateFormatter dateFromString:date]; return [dateFormatter dateFromString:date];
} }
+ (NSString *)buildISO8601StringFromDate:(NSDate *)date + (NSString *)buildISO8601StringFromDate:(NSDate *)date
{ {
NSDateFormatter *dateFormatter = [NSDateFormatter new]; NSDateFormatter *dateFormatter = [NSDateFormatter new];
NSLocale *posix = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]; NSLocale *posix = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
dateFormatter.locale = posix; dateFormatter.locale = posix;
// dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZZZZZ";
dateFormatter.dateFormat = @"yyyy'-'MM'-'dd'T'HH':'mm':'ss.SSSZ"; dateFormatter.dateFormat = @"yyyy'-'MM'-'dd'T'HH':'mm':'ss.SSSZ";
return [dateFormatter stringFromDate:date]; return [dateFormatter stringFromDate:date];
} }
+ (NSPredicate *)predicateForSamplesToday { + (NSPredicate *)predicateForSamplesToday {
NSDate *now = [NSDate date]; NSDate *now = [NSDate date];
return [RCTAppleHealthKit predicateForSamplesOnDay:now]; return [RCTAppleHealthKit predicateForSamplesOnDay:now];
} }
+ (NSPredicate *)predicateForSamplesOnDayFromTimestamp:(NSString *)timestamp { + (NSPredicate *)predicateForSamplesOnDayFromTimestamp:(NSString *)timestamp {
NSDate *day = [RCTAppleHealthKit parseISO8601DateFromString:timestamp]; NSDate *day = [RCTAppleHealthKit parseISO8601DateFromString:timestamp];
return [RCTAppleHealthKit predicateForSamplesOnDay:day]; return [RCTAppleHealthKit predicateForSamplesOnDay:day];
} }
+ (NSPredicate *)predicateForSamplesOnDay:(NSDate *)date { + (NSPredicate *)predicateForSamplesOnDay:(NSDate *)date {
NSCalendar *calendar = [NSCalendar currentCalendar]; NSCalendar *calendar = [NSCalendar currentCalendar];
NSDate *startDate = [calendar startOfDayForDate:date]; NSDate *startDate = [calendar startOfDayForDate:date];
...@@ -49,18 +52,12 @@ ...@@ -49,18 +52,12 @@
return [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionStrictStartDate]; return [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionStrictStartDate];
} }
+ (NSPredicate *)predicateForSamplesBetweenDates:(NSDate *)startDate endDate:(NSDate *)endDate { + (NSPredicate *)predicateForSamplesBetweenDates:(NSDate *)startDate endDate:(NSDate *)endDate {
// NSCalendar *calendar = [NSCalendar currentCalendar];
// NSDate *start = [calendar startOfDayForDate:startDate];
// NSDate *end = endDate;
// NSDate *endDate = [calendar dateByAddingUnit:NSCalendarUnitDay value:1 toDate:startDate options:0];
return [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionStrictStartDate]; return [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionStrictStartDate];
} }
+ (double)doubleValueFromOptions:(NSDictionary *)options { + (double)doubleValueFromOptions:(NSDictionary *)options {
double value = [[options objectForKey:@"value"] doubleValue]; double value = [[options objectForKey:@"value"] doubleValue];
return value; return value;
...@@ -76,6 +73,7 @@ ...@@ -76,6 +73,7 @@
return date; return date;
} }
+ (NSDate *)dateFromOptionsDefaultNow:(NSDictionary *)options { + (NSDate *)dateFromOptionsDefaultNow:(NSDictionary *)options {
NSString *dateString = [options objectForKey:@"date"]; NSString *dateString = [options objectForKey:@"date"];
if(dateString != nil){ if(dateString != nil){
...@@ -91,9 +89,6 @@ ...@@ -91,9 +89,6 @@
} }
//TODO: make a generic function that can return NSDate by key... have 'default now' as option
+ (NSDate *)startDateFromOptions:(NSDictionary *)options { + (NSDate *)startDateFromOptions:(NSDictionary *)options {
NSString *dateString = [options objectForKey:@"startDate"]; NSString *dateString = [options objectForKey:@"startDate"];
NSDate *date; NSDate *date;
...@@ -104,6 +99,7 @@ ...@@ -104,6 +99,7 @@
return date; return date;
} }
+ (NSDate *)endDateFromOptions:(NSDictionary *)options { + (NSDate *)endDateFromOptions:(NSDictionary *)options {
NSString *dateString = [options objectForKey:@"endDate"]; NSString *dateString = [options objectForKey:@"endDate"];
NSDate *date; NSDate *date;
...@@ -113,6 +109,7 @@ ...@@ -113,6 +109,7 @@
return date; return date;
} }
+ (NSDate *)endDateFromOptionsDefaultNow:(NSDictionary *)options { + (NSDate *)endDateFromOptionsDefaultNow:(NSDictionary *)options {
NSString *dateString = [options objectForKey:@"endDate"]; NSString *dateString = [options objectForKey:@"endDate"];
NSDate *date; NSDate *date;
...@@ -266,6 +263,7 @@ ...@@ -266,6 +263,7 @@
return val; return val;
} }
+ (double)doubleFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(double)defaultValue { + (double)doubleFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(double)defaultValue {
double val; double val;
NSNumber *num = [options objectForKey:key]; NSNumber *num = [options objectForKey:key];
...@@ -277,6 +275,7 @@ ...@@ -277,6 +275,7 @@
return val; return val;
} }
+ (NSDate *)dateFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(NSDate *)defaultValue { + (NSDate *)dateFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(NSDate *)defaultValue {
NSString *dateString = [options objectForKey:key]; NSString *dateString = [options objectForKey:key];
NSDate *date; NSDate *date;
...@@ -288,6 +287,7 @@ ...@@ -288,6 +287,7 @@
return date; return date;
} }
+ (NSString *)stringFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(NSString *)defaultValue { + (NSString *)stringFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(NSString *)defaultValue {
NSString *str = [options objectForKey:key]; NSString *str = [options objectForKey:key];
if(str == nil){ if(str == nil){
...@@ -296,6 +296,7 @@ ...@@ -296,6 +296,7 @@
return str; return str;
} }
+ (bool)boolFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(bool)defaultValue { + (bool)boolFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(bool)defaultValue {
NSNumber *num = [options objectForKey:key]; NSNumber *num = [options objectForKey:key];
if(num == nil){ if(num == nil){
...@@ -305,9 +306,6 @@ ...@@ -305,9 +306,6 @@
} }
+ (NSMutableArray *)reverseNSMutableArray:(NSMutableArray *)array { + (NSMutableArray *)reverseNSMutableArray:(NSMutableArray *)array {
if ([array count] <= 1) if ([array count] <= 1)
return array; return array;
...@@ -322,7 +320,4 @@ ...@@ -322,7 +320,4 @@
return array; return array;
} }
@end @end
...@@ -7,9 +7,7 @@ ...@@ -7,9 +7,7 @@
// //
#import "RCTAppleHealthKit.h" #import "RCTAppleHealthKit.h"
//#import "RCTAppleHealthKit+Queries.h"
#import "RCTAppleHealthKit+TypesAndPermissions.h" #import "RCTAppleHealthKit+TypesAndPermissions.h"
//#import "RCTAppleHealthKit+Utils.h"
#import "RCTAppleHealthKit+Methods_Body.h" #import "RCTAppleHealthKit+Methods_Body.h"
#import "RCTAppleHealthKit+Methods_Fitness.h" #import "RCTAppleHealthKit+Methods_Fitness.h"
...@@ -21,13 +19,10 @@ ...@@ -21,13 +19,10 @@
#import "RCTEventDispatcher.h" #import "RCTEventDispatcher.h"
@implementation RCTAppleHealthKit @implementation RCTAppleHealthKit
@synthesize bridge = _bridge; @synthesize bridge = _bridge;
RCT_EXPORT_MODULE(); RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(isAvailable:(RCTResponseSenderBlock)callback) RCT_EXPORT_METHOD(isAvailable:(RCTResponseSenderBlock)callback)
{ {
[self isHealthKitAvailable:callback]; [self isHealthKitAvailable:callback];
...@@ -68,7 +63,6 @@ RCT_EXPORT_METHOD(saveWeight:(NSDictionary *)input callback:(RCTResponseSenderBl ...@@ -68,7 +63,6 @@ RCT_EXPORT_METHOD(saveWeight:(NSDictionary *)input callback:(RCTResponseSenderBl
[self body_saveWeight:input callback:callback]; [self body_saveWeight:input callback:callback];
} }
RCT_EXPORT_METHOD(getLatestHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) RCT_EXPORT_METHOD(getLatestHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{ {
[self body_getLatestHeight:input callback:callback]; [self body_getLatestHeight:input callback:callback];
...@@ -84,7 +78,6 @@ RCT_EXPORT_METHOD(saveHeight:(NSDictionary *)input callback:(RCTResponseSenderBl ...@@ -84,7 +78,6 @@ RCT_EXPORT_METHOD(saveHeight:(NSDictionary *)input callback:(RCTResponseSenderBl
[self body_saveHeight:input callback:callback]; [self body_saveHeight:input callback:callback];
} }
RCT_EXPORT_METHOD(getLatestBmi:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) RCT_EXPORT_METHOD(getLatestBmi:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{ {
[self body_getLatestBodyMassIndex:input callback:callback]; [self body_getLatestBodyMassIndex:input callback:callback];
...@@ -95,7 +88,6 @@ RCT_EXPORT_METHOD(saveBmi:(NSDictionary *)input callback:(RCTResponseSenderBlock ...@@ -95,7 +88,6 @@ RCT_EXPORT_METHOD(saveBmi:(NSDictionary *)input callback:(RCTResponseSenderBlock
[self body_saveBodyMassIndex:input callback:callback]; [self body_saveBodyMassIndex:input callback:callback];
} }
RCT_EXPORT_METHOD(getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) RCT_EXPORT_METHOD(getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{ {
[self body_getLatestBodyFatPercentage:input callback:callback]; [self body_getLatestBodyFatPercentage:input callback:callback];
...@@ -106,22 +98,11 @@ RCT_EXPORT_METHOD(getLatestLeanBodyMass:(NSDictionary *)input callback:(RCTRespo ...@@ -106,22 +98,11 @@ RCT_EXPORT_METHOD(getLatestLeanBodyMass:(NSDictionary *)input callback:(RCTRespo
[self body_getLatestLeanBodyMass:input callback:callback]; [self body_getLatestLeanBodyMass:input callback:callback];
} }
//RCT_EXPORT_METHOD(getStepCountForToday:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
//{
// [self fitness_getStepCountForToday:input callback:callback];
//}
RCT_EXPORT_METHOD(getStepCount:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) RCT_EXPORT_METHOD(getStepCount:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{ {
[self fitness_getStepCountOnDay:input callback:callback]; [self fitness_getStepCountOnDay:input callback:callback];
} }
//RCT_EXPORT_METHOD(getMultiDayStepCounts:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
//{
// [self fitness_getDailyStepCounts: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];
...@@ -172,7 +153,6 @@ RCT_EXPORT_METHOD(getBloodGlucoseSamples:(NSDictionary *)input callback:(RCTResp ...@@ -172,7 +153,6 @@ RCT_EXPORT_METHOD(getBloodGlucoseSamples:(NSDictionary *)input callback:(RCTResp
[self results_getBloodGlucoseSamples:input callback:callback]; [self results_getBloodGlucoseSamples:input callback:callback];
} }
RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{ {
[self getModuleInfo:input callback:callback]; [self getModuleInfo:input callback:callback];
...@@ -239,7 +219,6 @@ RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock ...@@ -239,7 +219,6 @@ RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock
} }
} }
- (void)getModuleInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)getModuleInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
NSDictionary *info = @{ NSDictionary *info = @{
...@@ -251,5 +230,4 @@ RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock ...@@ -251,5 +230,4 @@ RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock
callback(@[[NSNull null], info]); callback(@[[NSNull null], info]);
} }
@end @end
...@@ -22,23 +22,4 @@ class StepsDemo extends Component { ...@@ -22,23 +22,4 @@ class StepsDemo extends Component {
} }
} }
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('StepsDemo', () => StepsDemo); AppRegistry.registerComponent('StepsDemo', () => StepsDemo);
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