Commit ca3d94b9 authored by Furyou81's avatar Furyou81
parents 66d0d625 5b51ff08
...@@ -35,8 +35,7 @@ ...@@ -35,8 +35,7 @@
callback(@[[NSNull null], results]); callback(@[[NSNull null], results]);
return; return;
} else { } else {
NSLog(@"error getting active energy burned samples: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"error getting active energy burned samples", nil, nil)]);
return; return;
} }
}]; }];
...@@ -65,8 +64,7 @@ ...@@ -65,8 +64,7 @@
callback(@[[NSNull null], results]); callback(@[[NSNull null], results]);
return; return;
} else { } else {
NSLog(@"error getting basal energy burned samples: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"error getting basal energy burned samples", nil, nil)]);
return; return;
} }
}]; }];
......
...@@ -23,6 +23,11 @@ ...@@ -23,6 +23,11 @@
- (void)body_saveHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)body_saveHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)body_getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getBodyFatPercentageSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_saveBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getLatestLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)body_getLatestLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getLeanBodyMassSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_saveLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
@end @end
...@@ -24,8 +24,7 @@ ...@@ -24,8 +24,7 @@
predicate:nil predicate:nil
completion:^(HKQuantity *mostRecentQuantity, NSDate *startDate, NSDate *endDate, NSError *error) { completion:^(HKQuantity *mostRecentQuantity, NSDate *startDate, NSDate *endDate, NSError *error) {
if (!mostRecentQuantity) { if (!mostRecentQuantity) {
NSLog(@"error getting latest weight: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"error getting latest weight", error, nil)]);
} }
else { else {
// Determine the weight in the required unit. // Determine the weight in the required unit.
...@@ -67,8 +66,7 @@ ...@@ -67,8 +66,7 @@
callback(@[[NSNull null], results]); callback(@[[NSNull null], results]);
return; return;
} else { } else {
NSLog(@"error getting weight samples: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"error getting weight samples", nil, nil)]);
return; return;
} }
}]; }];
...@@ -87,8 +85,7 @@ ...@@ -87,8 +85,7 @@
[self.healthStore saveObject:weightSample withCompletion:^(BOOL success, NSError *error) { [self.healthStore saveObject:weightSample withCompletion:^(BOOL success, NSError *error) {
if (!success) { if (!success) {
NSLog(@"error saving the weight sample: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"error saving the weight sample", error, nil)]);
return; return;
} }
callback(@[[NSNull null], @(weight)]); callback(@[[NSNull null], @(weight)]);
...@@ -104,8 +101,7 @@ ...@@ -104,8 +101,7 @@
predicate:nil predicate:nil
completion:^(HKQuantity *mostRecentQuantity, NSDate *startDate, NSDate *endDate, NSError *error) { completion:^(HKQuantity *mostRecentQuantity, NSDate *startDate, NSDate *endDate, NSError *error) {
if (!mostRecentQuantity) { if (!mostRecentQuantity) {
NSLog(@"error getting latest BMI: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"error getting latest BMI", error, nil)]);
} }
else { else {
// Determine the bmi in the required unit. // Determine the bmi in the required unit.
...@@ -136,8 +132,7 @@ ...@@ -136,8 +132,7 @@
[self.healthStore saveObject:bmiSample withCompletion:^(BOOL success, NSError *error) { [self.healthStore saveObject:bmiSample withCompletion:^(BOOL success, NSError *error) {
if (!success) { if (!success) {
NSLog(@"error saving BMI sample: %@.", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"error saving BMI sample", error, nil)]);
return; return;
} }
callback(@[[NSNull null], @(bmi)]); callback(@[[NSNull null], @(bmi)]);
...@@ -198,8 +193,7 @@ ...@@ -198,8 +193,7 @@
callback(@[[NSNull null], results]); callback(@[[NSNull null], results]);
return; return;
} else { } else {
NSLog(@"error getting height samples: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"error getting height samples", error, nil)]);
return; return;
} }
}]; }];
...@@ -218,8 +212,7 @@ ...@@ -218,8 +212,7 @@
[self.healthStore saveObject:heightSample withCompletion:^(BOOL success, NSError *error) { [self.healthStore saveObject:heightSample withCompletion:^(BOOL success, NSError *error) {
if (!success) { if (!success) {
NSLog(@"error saving height sample: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"error saving height sample", error, nil)]);
return; return;
} }
callback(@[[NSNull null], @(height)]); callback(@[[NSNull null], @(height)]);
...@@ -235,8 +228,7 @@ ...@@ -235,8 +228,7 @@
predicate:nil predicate:nil
completion:^(HKQuantity *mostRecentQuantity, NSDate *startDate, NSDate *endDate, NSError *error) { completion:^(HKQuantity *mostRecentQuantity, NSDate *startDate, NSDate *endDate, NSError *error) {
if (!mostRecentQuantity) { if (!mostRecentQuantity) {
NSLog(@"error getting latest body fat percentage: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"error getting latest body fat percentage", error, nil)]);
} }
else { else {
// Determine the weight in the required unit. // Determine the weight in the required unit.
...@@ -257,6 +249,62 @@ ...@@ -257,6 +249,62 @@
} }
- (void)body_getBodyFatPercentageSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKQuantityType *bodyFatPercentType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyFatPercentage];
HKUnit *unit = [HKUnit percentUnit];
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]];
if(startDate == nil){
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
return;
}
NSPredicate * predicate = [RCTAppleHealthKit predicateForSamplesBetweenDates:startDate endDate:endDate];
[self fetchQuantitySamplesOfType:bodyFatPercentType
unit:unit
predicate:predicate
ascending:ascending
limit:limit
completion:^(NSArray *results, NSError *error) {
if(results){
callback(@[[NSNull null], results]);
return;
} else {
NSLog(@"error getting body fat percentage samples: %@", error);
callback(@[RCTMakeError(@"error getting body fat percentage samples", nil, nil)]);
return;
}
}];
}
- (void)body_saveBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
double percentage = [RCTAppleHealthKit doubleValueFromOptions:input];
NSDate *sampleDate = [RCTAppleHealthKit dateFromOptionsDefaultNow:input];
HKUnit *unit = [HKUnit percentUnit];
percentage = percentage / 100;
HKQuantity *bodyFatPercentQuantity = [HKQuantity quantityWithUnit:unit doubleValue:percentage];
HKQuantityType *bodyFatPercentType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyFatPercentage];
HKQuantitySample *bodyFatPercentSample = [HKQuantitySample quantitySampleWithType:bodyFatPercentType quantity:bodyFatPercentQuantity startDate:sampleDate endDate:sampleDate];
[self.healthStore saveObject:bodyFatPercentSample withCompletion:^(BOOL success, NSError *error) {
if (!success) {
NSLog(@"error saving body fat percent sample: %@", error);
callback(@[RCTMakeError(@"error saving body fat percent sample", error, nil)]);
return;
}
callback(@[[NSNull null], @(percentage)]);
}];
}
- (void)body_getLatestLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)body_getLatestLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
HKQuantityType *leanBodyMassType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierLeanBodyMass]; HKQuantityType *leanBodyMassType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierLeanBodyMass];
...@@ -265,8 +313,7 @@ ...@@ -265,8 +313,7 @@
predicate:nil predicate:nil
completion:^(HKQuantity *mostRecentQuantity, NSDate *startDate, NSDate *endDate, NSError *error) { completion:^(HKQuantity *mostRecentQuantity, NSDate *startDate, NSDate *endDate, NSError *error) {
if (!mostRecentQuantity) { if (!mostRecentQuantity) {
NSLog(@"error getting latest lean body mass: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"error getting latest lean body mass", error, nil)]);
} }
else { else {
HKUnit *weightUnit = [HKUnit poundUnit]; HKUnit *weightUnit = [HKUnit poundUnit];
...@@ -283,4 +330,58 @@ ...@@ -283,4 +330,58 @@
}]; }];
} }
- (void)body_getLeanBodyMassSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKQuantityType *leanBodyMassType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierLeanBodyMass];
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit poundUnit]];
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]];
if(startDate == nil){
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
return;
}
NSPredicate * predicate = [RCTAppleHealthKit predicateForSamplesBetweenDates:startDate endDate:endDate];
[self fetchQuantitySamplesOfType:leanBodyMassType
unit:unit
predicate:predicate
ascending:ascending
limit:limit
completion:^(NSArray *results, NSError *error) {
if(results){
callback(@[[NSNull null], results]);
return;
} else {
NSLog(@"error getting lean body mass samples: %@", error);
callback(@[RCTMakeError(@"error getting lean body mass samples", nil, nil)]);
return;
}
}];
}
- (void)body_saveLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
double mass = [RCTAppleHealthKit doubleValueFromOptions:input];
NSDate *sampleDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:[NSDate date]];
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit poundUnit]];
HKQuantity *massQuantity = [HKQuantity quantityWithUnit:unit doubleValue:mass];
HKQuantityType *massType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierLeanBodyMass];
HKQuantitySample *massSample = [HKQuantitySample quantitySampleWithType:massType quantity:massQuantity startDate:sampleDate endDate:sampleDate];
[self.healthStore saveObject:massSample withCompletion:^(BOOL success, NSError *error) {
if (!success) {
NSLog(@"error saving lean body mass sample: %@", error);
callback(@[RCTMakeError(@"error saving lean body mass sample", error, nil)]);
return;
}
callback(@[[NSNull null], @(mass)]);
}];
}
@end @end
...@@ -34,8 +34,7 @@ ...@@ -34,8 +34,7 @@
} }
if(value == nil){ if(value == nil){
NSLog(@"error getting biological sex: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"error getting biological sex", error, nil)]);
return; return;
} }
...@@ -52,8 +51,7 @@ ...@@ -52,8 +51,7 @@
NSDate *dob = [self.healthStore dateOfBirthWithError:&error]; NSDate *dob = [self.healthStore dateOfBirthWithError:&error];
if(error != nil){ if(error != nil){
NSLog(@"error getting date of birth: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"error getting date of birth", error, nil)]);
return; return;
} }
if(dob == nil) { if(dob == nil) {
......
...@@ -34,8 +34,7 @@ ...@@ -34,8 +34,7 @@
day:date day:date
completion:^(double value, NSDate *startDate, NSDate *endDate, NSError *error) { completion:^(double value, NSDate *startDate, NSDate *endDate, NSError *error) {
if (!value) { if (!value) {
NSLog(@"could not fetch step count for day: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"could not fetch step count for day", error, nil)]);
return; return;
} }
...@@ -123,8 +122,7 @@ ...@@ -123,8 +122,7 @@
includeManuallyAdded:includeManuallyAdded includeManuallyAdded:includeManuallyAdded
completion:^(NSArray *arr, NSError *err){ completion:^(NSArray *arr, NSError *err){
if (err != nil) { if (err != nil) {
NSLog(@"error with fetchCumulativeSumStatisticsCollection: %@", err); callback(@[RCTJSErrorFromNSError(err)]);
callback(@[RCTMakeError(@"error with fetchCumulativeSumStatisticsCollection", err, nil)]);
return; return;
} }
callback(@[[NSNull null], arr]); callback(@[[NSNull null], arr]);
...@@ -150,8 +148,7 @@ ...@@ -150,8 +148,7 @@
[self.healthStore saveObject:sample withCompletion:^(BOOL success, NSError *error) { [self.healthStore saveObject:sample withCompletion:^(BOOL success, NSError *error) {
if (!success) { if (!success) {
NSLog(@"An error occured saving the step count sample %@. The error was: %@.", sample, error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"An error occured saving the step count sample", error, nil)]);
return; return;
} }
callback(@[[NSNull null], @(value)]); callback(@[[NSNull null], @(value)]);
...@@ -173,9 +170,7 @@ ...@@ -173,9 +170,7 @@
NSError *error) { NSError *error) {
if (error) { if (error) {
// Perform Proper Error Handling Here... callback(@[RCTJSErrorFromNSError(error)]);
NSLog(@"*** An error occured while setting up the stepCount observer. %@ ***", error.localizedDescription);
callback(@[RCTMakeError(@"An error occured while setting up the stepCount observer", error, nil)]);
return; return;
} }
...@@ -200,8 +195,7 @@ ...@@ -200,8 +195,7 @@
[self fetchSumOfSamplesOnDayForType:quantityType unit:unit day:date completion:^(double distance, NSDate *startDate, NSDate *endDate, NSError *error) { [self fetchSumOfSamplesOnDayForType:quantityType unit:unit day:date completion:^(double distance, NSDate *startDate, NSDate *endDate, NSError *error) {
if (!distance) { if (!distance) {
NSLog(@"ERROR getting DistanceWalkingRunning: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"ERROR getting DistanceWalkingRunning", error, nil)]);
return; return;
} }
...@@ -276,8 +270,7 @@ ...@@ -276,8 +270,7 @@
includeManuallyAdded:includeManuallyAdded includeManuallyAdded:includeManuallyAdded
completion:^(NSArray *arr, NSError *err){ completion:^(NSArray *arr, NSError *err){
if (err != nil) { if (err != nil) {
NSLog(@"error with fetchCumulativeSumStatisticsCollection: %@", err); callback(@[RCTJSErrorFromNSError(err)]);
callback(@[RCTMakeError(@"error with fetchCumulativeSumStatisticsCollection", err, nil)]);
return; return;
} }
callback(@[[NSNull null], arr]); callback(@[[NSNull null], arr]);
...@@ -293,8 +286,7 @@ ...@@ -293,8 +286,7 @@
[self fetchSumOfSamplesOnDayForType:quantityType unit:unit day:date completion:^(double distance, NSDate *startDate, NSDate *endDate, NSError *error) { [self fetchSumOfSamplesOnDayForType:quantityType unit:unit day:date completion:^(double distance, NSDate *startDate, NSDate *endDate, NSError *error) {
if (!distance) { if (!distance) {
NSLog(@"ERROR getting DistanceCycling: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"ERROR getting DistanceCycling", error, nil)]);
return; return;
} }
...@@ -334,8 +326,7 @@ ...@@ -334,8 +326,7 @@
includeManuallyAdded:includeManuallyAdded includeManuallyAdded:includeManuallyAdded
completion:^(NSArray *arr, NSError *err){ completion:^(NSArray *arr, NSError *err){
if (err != nil) { if (err != nil) {
NSLog(@"error with fetchCumulativeSumStatisticsCollection: %@", err); callback(@[RCTJSErrorFromNSError(err)]);
callback(@[RCTMakeError(@"error with fetchCumulativeSumStatisticsCollection", err, nil)]);
return; return;
} }
callback(@[[NSNull null], arr]); callback(@[[NSNull null], arr]);
...@@ -351,8 +342,7 @@ ...@@ -351,8 +342,7 @@
[self fetchSumOfSamplesOnDayForType:quantityType unit:unit day:date completion:^(double count, NSDate *startDate, NSDate *endDate, NSError *error) { [self fetchSumOfSamplesOnDayForType:quantityType unit:unit day:date completion:^(double count, NSDate *startDate, NSDate *endDate, NSError *error) {
if (!count) { if (!count) {
NSLog(@"ERROR getting FlightsClimbed: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"ERROR getting FlightsClimbed", error, nil), @(count)]);
return; return;
} }
...@@ -388,8 +378,7 @@ ...@@ -388,8 +378,7 @@
limit:limit limit:limit
completion:^(NSArray *arr, NSError *err){ completion:^(NSArray *arr, NSError *err){
if (err != nil) { if (err != nil) {
NSLog(@"error with fetchCumulativeSumStatisticsCollection: %@", err); callback(@[RCTJSErrorFromNSError(err)]);
callback(@[RCTMakeError(@"error with fetchCumulativeSumStatisticsCollection", err, nil)]);
return; return;
} }
callback(@[[NSNull null], arr]); callback(@[[NSNull null], arr]);
......
...@@ -29,8 +29,7 @@ ...@@ -29,8 +29,7 @@
[self.healthStore saveObject:sample withCompletion:^(BOOL success, NSError *error) { [self.healthStore saveObject:sample withCompletion:^(BOOL success, NSError *error) {
if (!success) { if (!success) {
NSLog(@"An error occured saving the mindful session sample %@. The error was: %@.", sample, error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"An error occured saving the mindful session sample", error, nil)]);
return; return;
} }
callback(@[[NSNull null], @(value)]); callback(@[[NSNull null], @(value)]);
......
...@@ -32,8 +32,7 @@ ...@@ -32,8 +32,7 @@
callback(@[[NSNull null], results]); callback(@[[NSNull null], results]);
return; return;
} else { } else {
NSLog(@"error getting blood glucose samples: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"error getting blood glucose samples", nil, nil)]);
return; return;
} }
}]; }];
......
...@@ -36,8 +36,7 @@ ...@@ -36,8 +36,7 @@
callback(@[[NSNull null], results]); callback(@[[NSNull null], results]);
return; return;
} else { } else {
NSLog(@"error getting sleep samples: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"error getting sleep samples", nil, nil)]);
return; return;
} }
}]; }];
......
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
callback(@[[NSNull null], results]); callback(@[[NSNull null], results]);
return; return;
} else { } else {
NSLog(@"error getting heart rate samples: %@", error); callback(@[RCTJSErrorFromNSError(error)]);
callback(@[RCTMakeError(@"error getting heart rate samples", nil, nil)]);
return; return;
} }
}]; }];
......
...@@ -15,5 +15,7 @@ ...@@ -15,5 +15,7 @@
- (NSDictionary *)writePermsDict; - (NSDictionary *)writePermsDict;
- (NSSet *)getReadPermsFromOptions:(NSArray *)options; - (NSSet *)getReadPermsFromOptions:(NSArray *)options;
- (NSSet *)getWritePermsFromOptions:(NSArray *)options; - (NSSet *)getWritePermsFromOptions:(NSArray *)options;
- (HKObjectType *)getWritePermFromString:(NSString *)string;
- (NSString *)getAuthorizationStatusString:(HKAuthorizationStatus)status;
@end @end
...@@ -153,4 +153,18 @@ ...@@ -153,4 +153,18 @@
return writePermSet; return writePermSet;
} }
- (HKObjectType *)getWritePermFromString:(NSString *)writePerm {
return [[self writePermsDict] objectForKey:writePerm];
}
- (NSString *)getAuthorizationStatusString:(HKAuthorizationStatus)status {
switch (status) {
case HKAuthorizationStatusNotDetermined:
return @"NotDetermined";
case HKAuthorizationStatusSharingDenied:
return @"SharingDenied";
case HKAuthorizationStatusSharingAuthorized:
return @"SharingAuthorized";
}
}
@end @end
...@@ -99,11 +99,31 @@ RCT_EXPORT_METHOD(getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCT ...@@ -99,11 +99,31 @@ RCT_EXPORT_METHOD(getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCT
[self body_getLatestBodyFatPercentage:input callback:callback]; [self body_getLatestBodyFatPercentage:input callback:callback];
} }
RCT_EXPORT_METHOD(getBodyFatPercentageSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self body_getBodyFatPercentageSamples:input callback:callback];
}
RCT_EXPORT_METHOD(saveBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self body_saveBodyFatPercentage:input callback:callback];
}
RCT_EXPORT_METHOD(getLatestLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) RCT_EXPORT_METHOD(getLatestLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{ {
[self body_getLatestLeanBodyMass:input callback:callback]; [self body_getLatestLeanBodyMass:input callback:callback];
} }
RCT_EXPORT_METHOD(getLeanBodyMassSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self body_getLeanBodyMassSamples:input callback:callback];
}
RCT_EXPORT_METHOD(saveLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self body_saveLeanBodyMass: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];
...@@ -271,9 +291,7 @@ RCT_EXPORT_METHOD(saveMindfulSession:(NSDictionary *)input callback:(RCTResponse ...@@ -271,9 +291,7 @@ RCT_EXPORT_METHOD(saveMindfulSession:(NSDictionary *)input callback:(RCTResponse
[self.healthStore requestAuthorizationToShareTypes:writeDataTypes readTypes:readDataTypes completion:^(BOOL success, NSError *error) { [self.healthStore requestAuthorizationToShareTypes:writeDataTypes readTypes:readDataTypes completion:^(BOOL success, NSError *error) {
if (!success) { if (!success) {
NSString *errMsg = [NSString stringWithFormat:@"Error with HealthKit authorization: %@", error]; callback(@[RCTJSErrorFromNSError(error)]);
NSLog(errMsg);
callback(@[RCTMakeError(errMsg, nil, nil)]);
return; return;
} else { } else {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
...@@ -286,6 +304,28 @@ RCT_EXPORT_METHOD(saveMindfulSession:(NSDictionary *)input callback:(RCTResponse ...@@ -286,6 +304,28 @@ RCT_EXPORT_METHOD(saveMindfulSession:(NSDictionary *)input callback:(RCTResponse
} }
} }
RCT_EXPORT_METHOD(authorizationStatusForType:(NSString *)type
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject
{
if (self.healthStore == nil) {
self.healthStore = [[HKHealthStore alloc] init];
}
if ([HKHealthStore isHealthDataAvailable]) {
HKObjectType *objectType = [self getWritePermFromString:type];
if (objectType == nil) {
reject(@"unknown write permission", nil, nil);
return;
}
NSString *status = [self getAuthorizationStatusString:[self.healthStore authorizationStatusForType:objectType]];
resolve(status);
} else {
reject(@"HealthKit data is not available", nil, nil);
}
})
- (void)getModuleInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)getModuleInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
NSDictionary *info = @{ NSDictionary *info = @{
......
...@@ -106,6 +106,7 @@ AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) => ...@@ -106,6 +106,7 @@ AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) =>
* Base Methods * Base Methods
* [isAvailable](/docs/isAvailable().md) * [isAvailable](/docs/isAvailable().md)
* [initHealthKit](/docs/initHealthKit().md) * [initHealthKit](/docs/initHealthKit().md)
* [authorizationStatusForType](/docs/authorizationStatusForType().md)
* Realtime Methods * Realtime Methods
* [initStepCountObserver](/docs/initStepCountObserver().md) * [initStepCountObserver](/docs/initStepCountObserver().md)
* [setObserver](/docs/setObserver().md) * [setObserver](/docs/setObserver().md)
...@@ -129,8 +130,10 @@ AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) => ...@@ -129,8 +130,10 @@ AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) =>
* [getHeightSamples](/docs/getHeightSamples().md) * [getHeightSamples](/docs/getHeightSamples().md)
* [getLatestBmi](/docs/getLatestBmi().md) * [getLatestBmi](/docs/getLatestBmi().md)
* [getLatestBodyFatPercentage](/docs/getLatestBodyFatPercentage().md) * [getLatestBodyFatPercentage](/docs/getLatestBodyFatPercentage().md)
* [getBodyFatPercentageSamples](/docs/getBodyFatPercentageSamples().md)
* [getLatestHeight](/docs/getLatestHeight().md) * [getLatestHeight](/docs/getLatestHeight().md)
* [getLatestLeanBodyMass](/docs/getLatestLeanBodyMass().md) * [getLatestLeanBodyMass](/docs/getLatestLeanBodyMass().md)
* [getLeanBodyMassSamples](/docs/getLeanBodyMassSamples().md)
* [getLatestWeight](/docs/getLatestWeight().md) * [getLatestWeight](/docs/getLatestWeight().md)
* [getRespiratoryRateSamples](/docs/getRespiratoryRateSamples().md) * [getRespiratoryRateSamples](/docs/getRespiratoryRateSamples().md)
* [getSleepSamples](/docs/getSleepSamples().md) * [getSleepSamples](/docs/getSleepSamples().md)
...@@ -143,6 +146,8 @@ AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) => ...@@ -143,6 +146,8 @@ AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) =>
* [saveMindfulSession](/docs/saveMindfulSession().md) * [saveMindfulSession](/docs/saveMindfulSession().md)
* [saveWeight](/docs/saveWeight().md) * [saveWeight](/docs/saveWeight().md)
* [saveSteps](/docs/saveSteps().md) * [saveSteps](/docs/saveSteps().md)
* [saveBodyFatPercentage](/docs/saveBodyFatPercentage().md)
* [saveLeanBodyMass](/docs/saveLeanBodyMass().md)
* [References](#references) * [References](#references)
## Supported Apple Permissions ## Supported Apple Permissions
...@@ -172,6 +177,7 @@ The available Healthkit permissions to use with `initHealthKit` ...@@ -172,6 +177,7 @@ The available Healthkit permissions to use with `initHealthKit`
| StepCount | [HKQuantityTypeIdentifierStepCount](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierstepcount?language=objc) | ✓ | ✓ | | StepCount | [HKQuantityTypeIdentifierStepCount](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierstepcount?language=objc) | ✓ | ✓ |
| Steps | [HKQuantityTypeIdentifierSteps](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifiersteps?language=objc) | ✓ | ✓ | | Steps | [HKQuantityTypeIdentifierSteps](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifiersteps?language=objc) | ✓ | ✓ |
| Weight | [HKQuantityTypeIdentifierBodyMass](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierbodymass?language=objc) | ✓ | ✓ | | Weight | [HKQuantityTypeIdentifierBodyMass](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierbodymass?language=objc) | ✓ | ✓ |
| BodyFatPercentage | [HKQuantityTypeIdentifierBodyFatPercentage](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierbodyfatpercentage?language=objc) | ✓ | ✓ |
These permissions are exported as constants of the `rn-apple-healthkit` module. These permissions are exported as constants of the `rn-apple-healthkit` module.
......
Check the authorization status for sharing (writing) the specified data type.
Status will be one of `"NotDetermined"`, `"SharingDenied"`, `"SharingAuthorized"`.
```javascript
try {
const status = await AppleHealthKit.authorizationStatusForType("StepCount")
if (status) {
console.log("status is", status)
}
} catch (error) {
console.warn(error)
}
```
There is no way to check authorization status for read permission, [see this](https://developer.apple.com/documentation/healthkit/hkhealthstore/1614154-authorizationstatusfortype?language=objc).
Query for body fat percentage samples. the options object is used to setup a query to retrieve relevant samples.
```javascript
let options = {
startDate: (new Date(2016,4,27)).toISOString(), // required
endDate: (new Date()).toISOString(), // optional; default now
ascending: false, // optional; default false
limit:10, // optional; default no limit
};
```
```javascript
AppleHealthKit.getBodyFatPercentageSamples(options, (err: Object, results: Array<Object>) => {
if (err) {
return;
}
console.log(results)
});
```
```javascript
[
{ value: 16.5, startDate: '2016-07-09T00:00:00.000-0400', endDate: '2016-07-10T00:00:00.000-0400' },
{ value: 16.1, startDate: '2016-07-08T00:00:00.000-0400', endDate: '2016-07-09T00:00:00.000-0400' },
{ value: 15.9, startDate: '2016-07-07T00:00:00.000-0400', endDate: '2016-07-08T00:00:00.000-0400' },
]
```
Query for lean body mass samples. the options object is used to setup a query to retrieve relevant samples.
```javascript
let options = {
unit: 'pound', // optional; default 'pound'
startDate: (new Date(2016,4,27)).toISOString(), // required
endDate: (new Date()).toISOString(), // optional; default now
ascending: false, // optional; default false
limit:10, // optional; default no limit
};
```
```javascript
AppleHealthKit.getLeanBodyMassSamples(options, (err: Object, results: Array<Object>) => {
if (err) {
return;
}
console.log(results)
});
```
```javascript
[
{ value: 160, startDate: '2016-07-09T00:00:00.000-0400', endDate: '2016-07-10T00:00:00.000-0400' },
{ value: 161, startDate: '2016-07-08T00:00:00.000-0400', endDate: '2016-07-09T00:00:00.000-0400' },
{ value: 165, startDate: '2016-07-07T00:00:00.000-0400', endDate: '2016-07-08T00:00:00.000-0400' },
]
```
save a percentage body fat value to Healthkit
`saveBodyFatPercentage` accepts an options object containing a percent value:
```javascript
let options = {
value: 16.7 // 16.7%
}
```
```javascript
AppleHealthKit.saveBodyFatPercentage(options: Object, (err: Object, results: Object) => {
if (err) {
return;
}
// body fat percentage successfully saved
});
```
save a numeric lean body mass value to Healthkit
`saveLeanBodyMass` accepts an options object containing a numeric weight value:
```javascript
let options = {
value: 155.6 // lbs
}
```
```javascript
AppleHealthKit.saveLeanBodyMass(options: Object, (err: Object, results: Object) => {
if (err) {
console.log("error saving lean body mass to Healthkit: ", err);
return;
}
// Done
});
```
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