From ddc8b04c17497e04463feab21630636fe1d48518 Mon Sep 17 00:00:00 2001 From: Greg Wilson Date: Thu, 13 Oct 2016 19:01:56 -0400 Subject: [PATCH] some clean up --- .../RCTAppleHealthKit+Methods_Body.h | 1 - .../RCTAppleHealthKit+Methods_Body.m | 11 ---- ...RCTAppleHealthKit+Methods_Characteristic.m | 2 - .../RCTAppleHealthKit+Methods_Fitness.h | 7 -- .../RCTAppleHealthKit+Methods_Fitness.m | 58 ----------------- .../RCTAppleHealthKit+Methods_Results.m | 2 +- .../RCTAppleHealthKit+Methods_Vitals.h | 3 - .../RCTAppleHealthKit+Methods_Vitals.m | 6 +- RCTAppleHealthKit/RCTAppleHealthKit+Queries.h | 8 --- RCTAppleHealthKit/RCTAppleHealthKit+Queries.m | 65 ++----------------- .../RCTAppleHealthKit+TypesAndPermissions.m | 10 ++- RCTAppleHealthKit/RCTAppleHealthKit+Utils.m | 31 ++++----- RCTAppleHealthKit/RCTAppleHealthKit.m | 22 ------- examples/StepsDemo/index.ios.js | 19 ------ 14 files changed, 26 insertions(+), 219 deletions(-) diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h index b0dc173..472829c 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h @@ -24,5 +24,4 @@ - (void)body_getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)body_getLatestLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m index c420020..f29f7f8 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m @@ -10,13 +10,11 @@ #import "RCTAppleHealthKit+Queries.h" #import "RCTAppleHealthKit+Utils.h" - @implementation RCTAppleHealthKit (Methods_Body) - (void)body_getLatestWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - // Query to get the user's latest weight, if it exists. HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass]; HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input]; @@ -80,8 +78,6 @@ } - - - (void)body_saveWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { double weight = [RCTAppleHealthKit doubleValueFromOptions:input]; @@ -105,7 +101,6 @@ - (void)body_getLatestBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - // Query to get the user's latest BMI, if it exists. HKQuantityType *bmiType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMassIndex]; [self fetchMostRecentQuantitySampleOfType:bmiType @@ -132,7 +127,6 @@ } - - (void)body_saveBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { double bmi = [RCTAppleHealthKit doubleValueFromOptions:input]; @@ -154,7 +148,6 @@ } - - (void)body_getLatestHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { HKQuantityType *heightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight]; @@ -187,7 +180,6 @@ } - - (void)body_getHeightSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { HKQuantityType *heightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight]; @@ -221,7 +213,6 @@ } - - (void)body_saveHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { double height = [RCTAppleHealthKit doubleValueFromOptions:input]; @@ -247,7 +238,6 @@ } - - (void)body_getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { HKQuantityType *bodyFatPercentType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyFatPercentage]; @@ -304,5 +294,4 @@ }]; } - @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.m index 358bc75..b7fb4f4 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.m @@ -78,6 +78,4 @@ callback(@[[NSNull null], response]); } - - @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h index a396875..60a9c6b 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h @@ -10,19 +10,12 @@ @interface RCTAppleHealthKit (Methods_Fitness) -//- (void)fitness_getStepCountForToday:(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_saveSteps:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - - (void)fitness_initializeStepEventObserver:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - - (void)fitness_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)fitness_getDistanceCyclingOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)fitness_getFlightsClimbedOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m index 3b5ae88..52a61b9 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m @@ -16,25 +16,6 @@ @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 { NSDate *date = [RCTAppleHealthKit dateFromOptions:input key:@"date" withDefault:[NSDate date]]; @@ -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 { HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit countUnit]]; @@ -131,7 +80,6 @@ } - - (void)fitness_saveSteps:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { double value = [RCTAppleHealthKit doubleFromOptions:input key:@"value" withDefault:(double)0]; @@ -159,7 +107,6 @@ } - - (void)fitness_initializeStepEventObserver:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { HKSampleType *sampleType = @@ -192,7 +139,6 @@ } - - (void)fitness_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit meterUnit]]; @@ -268,8 +214,4 @@ }]; } - - - - @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Results.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Results.m index 19c7c7c..fd5d034 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Results.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Results.m @@ -4,6 +4,7 @@ @implementation RCTAppleHealthKit (Methods_Results) + - (void)results_getBloodGlucoseSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { HKQuantityType *bloodGlucoseType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodGlucose]; @@ -38,5 +39,4 @@ }]; } - @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Vitals.h b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Vitals.h index 885f7be..db4df78 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Vitals.h +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Vitals.h @@ -3,11 +3,8 @@ @interface RCTAppleHealthKit (Methods_Vitals) - (void)vitals_getHeartRateSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - - (void)vitals_getBodyTemperatureSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - - (void)vitals_getBloodPressureSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - - (void)vitals_getRespiratoryRateSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Vitals.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Vitals.m index df52d83..74c53cb 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Vitals.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Vitals.m @@ -8,7 +8,7 @@ - (void)vitals_getHeartRateSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { HKQuantityType *heartRateType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate]; - + HKUnit *count = [HKUnit countUnit]; HKUnit *minute = [HKUnit minuteUnit]; @@ -40,6 +40,7 @@ }]; } + - (void)vitals_getBodyTemperatureSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { HKQuantityType *bodyTemperatureType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyTemperature]; @@ -116,7 +117,6 @@ [data addObject:elem]; } - callback(@[[NSNull null], data]); return; } else { @@ -127,6 +127,7 @@ }]; } + - (void)vitals_getRespiratoryRateSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { HKQuantityType *respiratoryRateType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierRespiratoryRate]; @@ -162,5 +163,4 @@ }]; } - @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.h b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.h index 69449c2..a5b9508 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.h +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.h @@ -13,30 +13,23 @@ - (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)fetchSumOfSamplesOnDayForType:(HKQuantityType *)quantityType unit:(HKUnit *)unit day:(NSDate *)day completion:(void (^)(double, NSDate *, NSDate *, NSError *))completionHandler; - - (void)fetchCumulativeSumStatisticsCollection:(HKQuantityType *)quantityType unit:(HKUnit *)unit startDate:(NSDate *)startDate endDate:(NSDate *)endDate completion:(void (^)(NSArray *, NSError *))completionHandler; - - - (void)fetchQuantitySamplesOfType:(HKQuantityType *)quantityType unit:(HKUnit *)unit predicate:(NSPredicate *)predicate ascending:(BOOL)asc limit:(NSUInteger)lim completion:(void (^)(NSArray *, NSError *))completion; - - - (void)fetchCorrelationSamplesOfType:(HKQuantityType *)quantityType unit:(HKUnit *)unit predicate:(NSPredicate *)predicate ascending:(BOOL)asc limit:(NSUInteger)lim completion:(void (^)(NSArray *, NSError *))completion; - - - (void)fetchCumulativeSumStatisticsCollection:(HKQuantityType *)quantityType unit:(HKUnit *)unit startDate:(NSDate *)startDate @@ -45,5 +38,4 @@ limit:(NSUInteger)lim completion:(void (^)(NSArray *, NSError *))completionHandler; - @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m index 41e6398..7b86134 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m @@ -49,7 +49,6 @@ } - - (void)fetchQuantitySamplesOfType:(HKQuantityType *)quantityType unit:(HKUnit *)unit predicate:(NSPredicate *)predicate @@ -97,7 +96,6 @@ } }; - HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:quantityType predicate:predicate limit:lim @@ -135,16 +133,14 @@ dispatch_async(dispatch_get_main_queue(), ^{ for (HKCorrelation *sample in results) { - NSString *startDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.startDate]; NSString *endDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.endDate]; NSDictionary *elem = @{ - @"correlation" : sample, - @"startDate" : startDateString, - @"endDate" : endDateString, - }; - + @"correlation" : sample, + @"startDate" : startDateString, + @"endDate" : endDateString, + }; [data addObject:elem]; } @@ -153,7 +149,6 @@ } }; - HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:quantityType predicate:predicate limit:lim @@ -164,10 +159,6 @@ } - - - - - (void)fetchSumOfSamplesTodayForType:(HKQuantityType *)quantityType unit:(HKUnit *)unit completion:(void (^)(double, NSError *))completionHandler { @@ -177,26 +168,17 @@ quantitySamplePredicate:predicate options:HKStatisticsOptionCumulativeSum completionHandler:^(HKStatisticsQuery *query, HKStatistics *result, NSError *error) { - HKQuantity *sum = [result sumQuantity]; if (completionHandler) { double value = [sum doubleValueForUnit:unit]; completionHandler(value, error); } - }]; - + [self.healthStore executeQuery:query]; } - - - - - - - - (void)fetchSumOfSamplesOnDayForType:(HKQuantityType *)quantityType unit:(HKUnit *)unit day:(NSDate *)day @@ -207,7 +189,6 @@ quantitySamplePredicate:predicate options:HKStatisticsOptionCumulativeSum completionHandler:^(HKStatisticsQuery *query, HKStatistics *result, NSError *error) { - HKQuantity *sum = [result sumQuantity]; NSDate *startDate = result.startDate; NSDate *endDate = result.endDate; @@ -215,20 +196,12 @@ double value = [sum doubleValueForUnit:unit]; completionHandler(value,startDate, endDate, error); } - }]; [self.healthStore executeQuery:query]; } - - - - - - - - (void)fetchCumulativeSumStatisticsCollection:(HKQuantityType *)quantityType unit:(HKUnit *)unit startDate:(NSDate *)startDate @@ -270,32 +243,18 @@ NSLog(@"%@: %f", date, value); NSString *dateString = [RCTAppleHealthKit buildISO8601StringFromDate:date]; - NSArray *elem = @[dateString, @(value)]; - [data addObject:elem]; } - }]; NSError *err; completionHandler(data, err); - }; [self.healthStore executeQuery:query]; } - - - - - - - - - - - (void)fetchCumulativeSumStatisticsCollection:(HKQuantityType *)quantityType unit:(HKUnit *)unit startDate:(NSDate *)startDate @@ -347,10 +306,8 @@ @"startDate" : startDateString, @"endDate" : endDateString, }; - [data addObject:elem]; } - }]; // is ascending by default if(asc == false) { @@ -370,16 +327,4 @@ [self.healthStore executeQuery:query]; } - - - - - - - - - - - - @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m b/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m index ac91a98..64f8fa2 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m @@ -10,6 +10,7 @@ @implementation RCTAppleHealthKit (TypesAndPermissions) + #pragma mark - HealthKit Permissions - (NSDictionary *)readPermsDict { @@ -48,6 +49,7 @@ return readPerms; } + - (NSDictionary *)writePermsDict { NSDictionary *writePerms = @{ // Body Measurements @@ -76,16 +78,14 @@ - (NSSet *)getReadPermsFromOptions:(NSArray *)options { NSDictionary *readPermDict = [self readPermsDict]; NSMutableSet *readPermSet = [NSMutableSet setWithCapacity:1]; - + for(int i=0; i<[options count]; i++) { NSString *optionKey = options[i]; HKObjectType *val = [readPermDict objectForKey:optionKey]; if(val != nil) { -// RCTLogInfo(@"Adding read permissions from options: %@", optionKey); [readPermSet addObject:val]; } } - return readPermSet; } @@ -94,16 +94,14 @@ - (NSSet *)getWritePermsFromOptions:(NSArray *)options { NSDictionary *writePermDict = [self writePermsDict]; NSMutableSet *writePermSet = [NSMutableSet setWithCapacity:1]; - + for(int i=0; i<[options count]; i++) { NSString *optionKey = options[i]; HKObjectType *val = [writePermDict objectForKey:optionKey]; if(val != nil) { -// RCTLogInfo(@"Adding write permissions from options: %@", optionKey); [writePermSet addObject:val]; } } - return writePermSet; } diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Utils.m b/RCTAppleHealthKit/RCTAppleHealthKit+Utils.m index 51e3f63..9ffb096 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Utils.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Utils.m @@ -10,6 +10,7 @@ @implementation RCTAppleHealthKit (Utils) + #pragma mark - Utilities + (NSDate *)parseISO8601DateFromString:(NSString *)date @@ -17,31 +18,33 @@ NSDateFormatter *dateFormatter = [NSDateFormatter new]; NSLocale *posix = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]; dateFormatter.locale = posix; -// dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZZZZZ"; dateFormatter.dateFormat = @"yyyy'-'MM'-'dd'T'HH':'mm':'ss.SSSZ"; return [dateFormatter dateFromString:date]; } + + (NSString *)buildISO8601StringFromDate:(NSDate *)date { NSDateFormatter *dateFormatter = [NSDateFormatter new]; NSLocale *posix = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]; dateFormatter.locale = posix; -// dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZZZZZ"; dateFormatter.dateFormat = @"yyyy'-'MM'-'dd'T'HH':'mm':'ss.SSSZ"; return [dateFormatter stringFromDate:date]; } + + (NSPredicate *)predicateForSamplesToday { NSDate *now = [NSDate date]; return [RCTAppleHealthKit predicateForSamplesOnDay:now]; } + + (NSPredicate *)predicateForSamplesOnDayFromTimestamp:(NSString *)timestamp { NSDate *day = [RCTAppleHealthKit parseISO8601DateFromString:timestamp]; return [RCTAppleHealthKit predicateForSamplesOnDay:day]; } + + (NSPredicate *)predicateForSamplesOnDay:(NSDate *)date { NSCalendar *calendar = [NSCalendar currentCalendar]; NSDate *startDate = [calendar startOfDayForDate:date]; @@ -49,18 +52,12 @@ return [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionStrictStartDate]; } + + (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]; } - - - + (double)doubleValueFromOptions:(NSDictionary *)options { double value = [[options objectForKey:@"value"] doubleValue]; return value; @@ -76,6 +73,7 @@ return date; } + + (NSDate *)dateFromOptionsDefaultNow:(NSDictionary *)options { NSString *dateString = [options objectForKey:@"date"]; if(dateString != nil){ @@ -91,9 +89,6 @@ } -//TODO: make a generic function that can return NSDate by key... have 'default now' as option - - + (NSDate *)startDateFromOptions:(NSDictionary *)options { NSString *dateString = [options objectForKey:@"startDate"]; NSDate *date; @@ -104,6 +99,7 @@ return date; } + + (NSDate *)endDateFromOptions:(NSDictionary *)options { NSString *dateString = [options objectForKey:@"endDate"]; NSDate *date; @@ -113,6 +109,7 @@ return date; } + + (NSDate *)endDateFromOptionsDefaultNow:(NSDictionary *)options { NSString *dateString = [options objectForKey:@"endDate"]; NSDate *date; @@ -266,6 +263,7 @@ return val; } + + (double)doubleFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(double)defaultValue { double val; NSNumber *num = [options objectForKey:key]; @@ -277,6 +275,7 @@ return val; } + + (NSDate *)dateFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(NSDate *)defaultValue { NSString *dateString = [options objectForKey:key]; NSDate *date; @@ -288,6 +287,7 @@ return date; } + + (NSString *)stringFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(NSString *)defaultValue { NSString *str = [options objectForKey:key]; if(str == nil){ @@ -296,6 +296,7 @@ return str; } + + (bool)boolFromOptions:(NSDictionary *)options key:(NSString *)key withDefault:(bool)defaultValue { NSNumber *num = [options objectForKey:key]; if(num == nil){ @@ -305,9 +306,6 @@ } - - - + (NSMutableArray *)reverseNSMutableArray:(NSMutableArray *)array { if ([array count] <= 1) return array; @@ -322,7 +320,4 @@ return array; } - - - @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit.m b/RCTAppleHealthKit/RCTAppleHealthKit.m index 036881b..8b6b134 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit.m @@ -7,9 +7,7 @@ // #import "RCTAppleHealthKit.h" -//#import "RCTAppleHealthKit+Queries.h" #import "RCTAppleHealthKit+TypesAndPermissions.h" -//#import "RCTAppleHealthKit+Utils.h" #import "RCTAppleHealthKit+Methods_Body.h" #import "RCTAppleHealthKit+Methods_Fitness.h" @@ -21,13 +19,10 @@ #import "RCTEventDispatcher.h" @implementation RCTAppleHealthKit - @synthesize bridge = _bridge; - RCT_EXPORT_MODULE(); - RCT_EXPORT_METHOD(isAvailable:(RCTResponseSenderBlock)callback) { [self isHealthKitAvailable:callback]; @@ -68,7 +63,6 @@ RCT_EXPORT_METHOD(saveWeight:(NSDictionary *)input callback:(RCTResponseSenderBl [self body_saveWeight:input callback:callback]; } - RCT_EXPORT_METHOD(getLatestHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self body_getLatestHeight:input callback:callback]; @@ -84,7 +78,6 @@ RCT_EXPORT_METHOD(saveHeight:(NSDictionary *)input callback:(RCTResponseSenderBl [self body_saveHeight:input callback:callback]; } - RCT_EXPORT_METHOD(getLatestBmi:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self body_getLatestBodyMassIndex:input callback:callback]; @@ -95,7 +88,6 @@ RCT_EXPORT_METHOD(saveBmi:(NSDictionary *)input callback:(RCTResponseSenderBlock [self body_saveBodyMassIndex:input callback:callback]; } - RCT_EXPORT_METHOD(getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self body_getLatestBodyFatPercentage:input callback:callback]; @@ -106,22 +98,11 @@ RCT_EXPORT_METHOD(getLatestLeanBodyMass:(NSDictionary *)input callback:(RCTRespo [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) { [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) { [self fitness_getDailyStepSamples:input callback:callback]; @@ -172,7 +153,6 @@ RCT_EXPORT_METHOD(getBloodGlucoseSamples:(NSDictionary *)input callback:(RCTResp [self results_getBloodGlucoseSamples:input callback:callback]; } - RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self getModuleInfo:input callback:callback]; @@ -239,7 +219,6 @@ RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock } } - - (void)getModuleInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSDictionary *info = @{ @@ -251,5 +230,4 @@ RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock callback(@[[NSNull null], info]); } - @end diff --git a/examples/StepsDemo/index.ios.js b/examples/StepsDemo/index.ios.js index f4566ce..9250cd3 100644 --- a/examples/StepsDemo/index.ios.js +++ b/examples/StepsDemo/index.ios.js @@ -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); -- 2.26.2