diff --git a/RCTAppleHealthKit.xcodeproj/project.pbxproj b/RCTAppleHealthKit.xcodeproj/project.pbxproj index 6ef3d6e66ba402c1da4ba8191eec62e948bd6912..073f1be72c5026f28934346cdf5f86843470fcd2 100644 --- a/RCTAppleHealthKit.xcodeproj/project.pbxproj +++ b/RCTAppleHealthKit.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 3774C89B1D2095450000B3F3 /* RCTAppleHealthKit+Queries.m in Sources */ = {isa = PBXBuildFile; fileRef = 3774C89A1D2095450000B3F3 /* RCTAppleHealthKit+Queries.m */; }; 3774C89E1D2095850000B3F3 /* RCTAppleHealthKit+TypesAndPermissions.m in Sources */ = {isa = PBXBuildFile; fileRef = 3774C89D1D2095850000B3F3 /* RCTAppleHealthKit+TypesAndPermissions.m */; }; 3774C8A11D20A6B90000B3F3 /* RCTAppleHealthKit+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 3774C8A01D20A6B90000B3F3 /* RCTAppleHealthKit+Utils.m */; }; + 3774C8D41D20C6390000B3F3 /* RCTAppleHealthKit+Methods_Body.m in Sources */ = {isa = PBXBuildFile; fileRef = 3774C8D31D20C6390000B3F3 /* RCTAppleHealthKit+Methods_Body.m */; }; + 3774C8D71D20C65F0000B3F3 /* RCTAppleHealthKit+Methods_Fitness.m in Sources */ = {isa = PBXBuildFile; fileRef = 3774C8D61D20C65F0000B3F3 /* RCTAppleHealthKit+Methods_Fitness.m */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -37,6 +39,10 @@ 3774C89D1D2095850000B3F3 /* RCTAppleHealthKit+TypesAndPermissions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTAppleHealthKit+TypesAndPermissions.m"; sourceTree = ""; }; 3774C89F1D20A6B90000B3F3 /* RCTAppleHealthKit+Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTAppleHealthKit+Utils.h"; sourceTree = ""; }; 3774C8A01D20A6B90000B3F3 /* RCTAppleHealthKit+Utils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTAppleHealthKit+Utils.m"; sourceTree = ""; }; + 3774C8D21D20C6390000B3F3 /* RCTAppleHealthKit+Methods_Body.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTAppleHealthKit+Methods_Body.h"; sourceTree = ""; }; + 3774C8D31D20C6390000B3F3 /* RCTAppleHealthKit+Methods_Body.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTAppleHealthKit+Methods_Body.m"; sourceTree = ""; }; + 3774C8D51D20C65F0000B3F3 /* RCTAppleHealthKit+Methods_Fitness.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTAppleHealthKit+Methods_Fitness.h"; sourceTree = ""; }; + 3774C8D61D20C65F0000B3F3 /* RCTAppleHealthKit+Methods_Fitness.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTAppleHealthKit+Methods_Fitness.m"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -77,6 +83,10 @@ 3774C89D1D2095850000B3F3 /* RCTAppleHealthKit+TypesAndPermissions.m */, 3774C89F1D20A6B90000B3F3 /* RCTAppleHealthKit+Utils.h */, 3774C8A01D20A6B90000B3F3 /* RCTAppleHealthKit+Utils.m */, + 3774C8D21D20C6390000B3F3 /* RCTAppleHealthKit+Methods_Body.h */, + 3774C8D31D20C6390000B3F3 /* RCTAppleHealthKit+Methods_Body.m */, + 3774C8D51D20C65F0000B3F3 /* RCTAppleHealthKit+Methods_Fitness.h */, + 3774C8D61D20C65F0000B3F3 /* RCTAppleHealthKit+Methods_Fitness.m */, ); path = RCTAppleHealthKit; sourceTree = ""; @@ -139,8 +149,10 @@ files = ( 3774C89B1D2095450000B3F3 /* RCTAppleHealthKit+Queries.m in Sources */, 3774C8A11D20A6B90000B3F3 /* RCTAppleHealthKit+Utils.m in Sources */, + 3774C8D41D20C6390000B3F3 /* RCTAppleHealthKit+Methods_Body.m in Sources */, 3774C8931D2092F20000B3F3 /* RCTAppleHealthKit.m in Sources */, 3774C89E1D2095850000B3F3 /* RCTAppleHealthKit+TypesAndPermissions.m in Sources */, + 3774C8D71D20C65F0000B3F3 /* RCTAppleHealthKit+Methods_Fitness.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h new file mode 100644 index 0000000000000000000000000000000000000000..fcff8efc1e7fcf2f32684190a4abca93e2fa4800 --- /dev/null +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h @@ -0,0 +1,16 @@ +// +// RCTAppleHealthKit+Methods_Body.h +// RCTAppleHealthKit +// +// Created by Greg Wilson on 2016-06-26. +// Copyright © 2016 Greg Wilson. All rights reserved. +// + +#import "RCTAppleHealthKit.h" + +@interface RCTAppleHealthKit (Methods_Body) + +- (void)body_getCurrentWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)body_saveWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + +@end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m new file mode 100644 index 0000000000000000000000000000000000000000..1ec97c1d56800f4bd15ca95b0bddd0da9cf1de0e --- /dev/null +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m @@ -0,0 +1,60 @@ +// +// RCTAppleHealthKit+Methods_Body.m +// RCTAppleHealthKit +// +// Created by Greg Wilson on 2016-06-26. +// Copyright © 2016 Greg Wilson. All rights reserved. +// + +#import "RCTAppleHealthKit+Methods_Body.h" +#import "RCTAppleHealthKit+Queries.h" + +@implementation RCTAppleHealthKit (Methods_Body) + +- (void)body_getCurrentWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback +{ + // Query to get the user's latest weight, if it exists. + HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass]; + + [self fetchMostRecentQuantitySampleOfType:weightType predicate:nil completion:^(HKQuantity *mostRecentQuantity, NSError *error) { + if (!mostRecentQuantity) { + NSLog(@"Either an error occured fetching the user's weight 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 weight information or none has been stored yet. In your app, try to handle this gracefully.", nil, nil)]); + } + else { + // Determine the weight in the required unit. + HKUnit *weightUnit = [HKUnit poundUnit]; + double usersWeight = [mostRecentQuantity doubleValueForUnit:weightUnit]; + + callback(@[[NSNull null], @(usersWeight)]); + } + }]; +} + + + + +- (void)body_saveWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback +{ + double weight= [[input objectForKey:@"weight"] doubleValue]; + + HKUnit *poundUnit = [HKUnit poundUnit]; + HKQuantity *weightQuantity = [HKQuantity quantityWithUnit:poundUnit doubleValue:weight]; + + HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass]; + NSDate *now = [NSDate date]; + + HKQuantitySample *weightSample = [HKQuantitySample quantitySampleWithType:weightType quantity:weightQuantity startDate:now endDate:now]; + + [self.healthStore saveObject:weightSample withCompletion:^(BOOL success, NSError *error) { + if (!success) { + NSLog(@"An error occured saving the weight sample %@. In your app, try to handle this gracefully. The error was: %@.", weightSample, error); + callback(@[RCTMakeError(@"An error occured saving the weight sample", nil, nil)]); + return; + // abort(); + } + callback(@[[NSNull null], @(weight)]); + }]; +} + +@end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h new file mode 100644 index 0000000000000000000000000000000000000000..150f2745aaa8e2c520c7e72d3825a189121d9498 --- /dev/null +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h @@ -0,0 +1,15 @@ +// +// RCTAppleHealthKit+Methods_Fitness.h +// RCTAppleHealthKit +// +// Created by Greg Wilson on 2016-06-26. +// Copyright © 2016 Greg Wilson. All rights reserved. +// + +#import "RCTAppleHealthKit.h" + +@interface RCTAppleHealthKit (Methods_Fitness) + +- (void)fitness_getStepCountForToday:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + +@end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m new file mode 100644 index 0000000000000000000000000000000000000000..31ac748ce524b6430b2d45a2238391f72f80e2dd --- /dev/null +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m @@ -0,0 +1,30 @@ +// +// RCTAppleHealthKit+Methods_Fitness.m +// RCTAppleHealthKit +// +// Created by Greg Wilson on 2016-06-26. +// Copyright © 2016 Greg Wilson. All rights reserved. +// + +#import "RCTAppleHealthKit+Methods_Fitness.h" +#import "RCTAppleHealthKit+Queries.h" + +@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)]); + }]; +} + +@end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m index 2dba35bf169e21de6dbe48000295764462958a76..172615ed29bcb0e8c6fe11b9f44888e219ea5c57 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m @@ -13,29 +13,26 @@ - (void)fetchMostRecentQuantitySampleOfType:(HKQuantityType *)quantityType predicate:(NSPredicate *)predicate completion:(void (^)(HKQuantity *, NSError *))completion { NSSortDescriptor *timeSortDescriptor = [[NSSortDescriptor alloc] initWithKey:HKSampleSortIdentifierEndDate ascending:NO]; - - // Since we are interested in retrieving the user's latest sample, we sort the samples in descending order, and set the limit to 1. We are not filtering the data, and so the predicate is set to nil. + HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:quantityType - predicate:predicate - limit:1 - sortDescriptors:@[timeSortDescriptor] - resultsHandler:^(HKSampleQuery *query, NSArray *results, NSError *error) { - if (!results) { - if (completion) { - completion(nil, error); - } - - return; - } - + predicate:predicate + limit:1 + sortDescriptors:@[timeSortDescriptor] + resultsHandler:^(HKSampleQuery *query, NSArray *results, NSError *error) { + if (!results) { if (completion) { - // If quantity isn't in the database, return nil in the completion block. - HKQuantitySample *quantitySample = results.firstObject; - HKQuantity *quantity = quantitySample.quantity; - - completion(quantity, error); + completion(nil, error); } - }]; + return; + } + + if (completion) { + // If quantity isn't in the database, return nil in the completion block. + HKQuantitySample *quantitySample = results.firstObject; + HKQuantity *quantity = quantitySample.quantity; + completion(quantity, error); + } + }]; [self.healthStore executeQuery:query]; } @@ -45,12 +42,14 @@ - (void)fetchSumOfSamplesTodayForType:(HKQuantityType *)quantityType unit:(HKUnit *)unit completion:(void (^)(double, NSError *))completionHandler { NSPredicate *predicate = [RCTAppleHealthKit predicateForSamplesToday]; - HKStatisticsQuery *query = [[HKStatisticsQuery alloc] initWithQuantityType:quantityType quantitySamplePredicate:predicate options:HKStatisticsOptionCumulativeSum completionHandler:^(HKStatisticsQuery *query, HKStatistics *result, NSError *error) { + HKStatisticsQuery *query = [[HKStatisticsQuery alloc] initWithQuantityType:quantityType + 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); } }]; diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m b/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m index c940a0f639f670091fa1ff4ae1496f15292aa820..f5296139906ce51fbb585fdb3b649100a648a3ec 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m @@ -80,7 +80,6 @@ } return readPermSet; - // return [self dataTypesToRead]; } @@ -99,7 +98,6 @@ } return writePermSet; - // return [self dataTypesToWrite]; } @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit.h b/RCTAppleHealthKit/RCTAppleHealthKit.h index 66b9b3a63f283f65ad2f0be7a174257a3ee02058..f18442d7e5c5529ca2763d5587f25fa16c6d3786 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit.h +++ b/RCTAppleHealthKit/RCTAppleHealthKit.h @@ -18,9 +18,9 @@ - (void)isHealthKitAvailable:(RCTResponseSenderBlock)callback; - (void)initializeHealthKit:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)getHealthKitUserWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)saveHealthKitUserWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)getHealthKitUserStepCount:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +//- (void)getHealthKitUserWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +//- (void)saveHealthKitUserWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +//- (void)getHealthKitUserStepCount:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)getModuleInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit.m b/RCTAppleHealthKit/RCTAppleHealthKit.m index e2efcd902df0e093ce3dd24adf027ddcdda8f4ab..5248fca6ca1de252e71068f8cc98b8fc4db6e4a7 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit.m @@ -11,6 +11,9 @@ #import "RCTAppleHealthKit+TypesAndPermissions.h" #import "RCTAppleHealthKit+Utils.h" +#import "RCTAppleHealthKit+Methods_Body.h" +#import "RCTAppleHealthKit+Methods_Fitness.h" + @implementation RCTAppleHealthKit RCT_EXPORT_MODULE(); @@ -28,17 +31,17 @@ RCT_EXPORT_METHOD(initHealthKit:(NSDictionary *)input callback:(RCTResponseSende RCT_EXPORT_METHOD(getCurrentWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { - [self getHealthKitUserWeight:input callback:callback]; + [self body_getCurrentWeight:input callback:callback]; } RCT_EXPORT_METHOD(saveWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { - [self saveHealthKitUserWeight:input callback:callback]; + [self body_saveWeight:input callback:callback]; } RCT_EXPORT_METHOD(getStepCountForToday:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { - [self getHealthKitUserStepCount:input callback:callback]; + [self fitness_getStepCountForToday:input callback:callback]; } RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) @@ -66,7 +69,7 @@ RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock NSSet *writeDataTypes = [self dataTypesToWrite]; NSSet *readDataTypes = [self dataTypesToRead]; - // get permissions from input object provided by JS options object argument + // get permissions from input object provided by JS options argument NSDictionary* permissions =[input objectForKey:@"permissions"]; if(permissions != nil){ NSArray* readPermsArray = [permissions objectForKey:@"read"]; @@ -94,82 +97,80 @@ RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock callback(@[[NSNull null], @true]); }); } - - }]; } else { callback(@[RCTMakeError(@"HealthKit not available....", nil, nil)]); } } +// +//- (void)getHealthKitUserWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback +//{ +//// NSMassFormatter *massFormatter = [[NSMassFormatter alloc] init]; +//// massFormatter.unitStyle = NSFormattingUnitStyleLong; +// +// // NSMassFormatterUnit weightFormatterUnit = NSMassFormatterUnitPound; +// // NSString *weightUnitString = [massFormatter unitStringFromValue:10 unit:weightFormatterUnit]; +// // NSString *localizedWeightUnitDescriptionFormat = NSLocalizedString(@"Weight (%@)", nil); +// +// // Query to get the user's latest weight, if it exists. +// HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass]; +// +// [self fetchMostRecentQuantitySampleOfType:weightType predicate:nil completion:^(HKQuantity *mostRecentQuantity, NSError *error) { +// if (!mostRecentQuantity) { +// NSLog(@"Either an error occured fetching the user's weight 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 weight information or none has been stored yet. In your app, try to handle this gracefully.", nil, nil)]); +// } +// else { +// // Determine the weight in the required unit. +// HKUnit *weightUnit = [HKUnit poundUnit]; +// double usersWeight = [mostRecentQuantity doubleValueForUnit:weightUnit]; +// +// callback(@[[NSNull null], @(usersWeight)]); +// } +// }]; +//} -- (void)getHealthKitUserWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback -{ -// NSMassFormatter *massFormatter = [[NSMassFormatter alloc] init]; -// massFormatter.unitStyle = NSFormattingUnitStyleLong; - - // NSMassFormatterUnit weightFormatterUnit = NSMassFormatterUnitPound; - // NSString *weightUnitString = [massFormatter unitStringFromValue:10 unit:weightFormatterUnit]; - // NSString *localizedWeightUnitDescriptionFormat = NSLocalizedString(@"Weight (%@)", nil); - - // Query to get the user's latest weight, if it exists. - HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass]; - - [self fetchMostRecentQuantitySampleOfType:weightType predicate:nil completion:^(HKQuantity *mostRecentQuantity, NSError *error) { - if (!mostRecentQuantity) { - NSLog(@"Either an error occured fetching the user's weight 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 weight information or none has been stored yet. In your app, try to handle this gracefully.", nil, nil)]); - } - else { - // Determine the weight in the required unit. - HKUnit *weightUnit = [HKUnit poundUnit]; - double usersWeight = [mostRecentQuantity doubleValueForUnit:weightUnit]; - - callback(@[[NSNull null], @(usersWeight)]); - } - }]; -} - - -- (void)saveHealthKitUserWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback -{ - double weight= [[input objectForKey:@"weight"] doubleValue]; - - HKUnit *poundUnit = [HKUnit poundUnit]; - HKQuantity *weightQuantity = [HKQuantity quantityWithUnit:poundUnit doubleValue:weight]; - - HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass]; - NSDate *now = [NSDate date]; - - HKQuantitySample *weightSample = [HKQuantitySample quantitySampleWithType:weightType quantity:weightQuantity startDate:now endDate:now]; - - [self.healthStore saveObject:weightSample withCompletion:^(BOOL success, NSError *error) { - if (!success) { - NSLog(@"An error occured saving the weight sample %@. In your app, try to handle this gracefully. The error was: %@.", weightSample, error); - callback(@[RCTMakeError(@"An error occured saving the weight sample", nil, nil)]); - return; - // abort(); - } - callback(@[[NSNull null], @(weight)]); - }]; -} - - -- (void)getHealthKitUserStepCount:(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)saveHealthKitUserWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback +//{ +// double weight= [[input objectForKey:@"weight"] doubleValue]; +// +// HKUnit *poundUnit = [HKUnit poundUnit]; +// HKQuantity *weightQuantity = [HKQuantity quantityWithUnit:poundUnit doubleValue:weight]; +// +// HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass]; +// NSDate *now = [NSDate date]; +// +// HKQuantitySample *weightSample = [HKQuantitySample quantitySampleWithType:weightType quantity:weightQuantity startDate:now endDate:now]; +// +// [self.healthStore saveObject:weightSample withCompletion:^(BOOL success, NSError *error) { +// if (!success) { +// NSLog(@"An error occured saving the weight sample %@. In your app, try to handle this gracefully. The error was: %@.", weightSample, error); +// callback(@[RCTMakeError(@"An error occured saving the weight sample", nil, nil)]); +// return; +// // abort(); +// } +// callback(@[[NSNull null], @(weight)]); +// }]; +//} + + +//- (void)getHealthKitUserStepCount:(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)]); +// }]; +//}