Commit 7ea9922a authored by Greg Wilson's avatar Greg Wilson

added getter methods for BodyFatPercentage and LeanBodyMass and Height

parent 23e876f0
...@@ -15,4 +15,9 @@ ...@@ -15,4 +15,9 @@
- (void)body_getLatestBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)body_getLatestBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getMostRecentHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getMostRecentBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getMostRecentLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
@end @end
...@@ -84,4 +84,65 @@ ...@@ -84,4 +84,65 @@
} }
- (void)body_getMostRecentHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKQuantityType *heightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight];
[self fetchMostRecentQuantitySampleOfType:heightType predicate:nil completion:^(HKQuantity *mostRecentQuantity, NSDate *startDate, NSDate *endDate, NSError *error) {
if (!mostRecentQuantity) {
NSLog(@"Either an error occured fetching the user's height 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 height 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 *heightUnit = [HKUnit inchUnit];
double usersHeight = [mostRecentQuantity doubleValueForUnit:heightUnit];
callback(@[[NSNull null], @(usersHeight)]);
}
}];
}
- (void)body_getMostRecentBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKQuantityType *bodyFatPercentType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyFatPercentage];
[self fetchMostRecentQuantitySampleOfType:bodyFatPercentType predicate:nil completion:^(HKQuantity *mostRecentQuantity, NSDate *startDate, NSDate *endDate, NSError *error) {
if (!mostRecentQuantity) {
NSLog(@"Either an error occured fetching the user's BodyFatPercentage 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 BodyFatPercentage 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 *percentUnit = [HKUnit percentUnit];
double percentage = [mostRecentQuantity doubleValueForUnit:percentUnit];
percentage = percentage * 100;
callback(@[[NSNull null], @(percentage)]);
}
}];
}
- (void)body_getMostRecentLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKQuantityType *leanBodyMassType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierLeanBodyMass];
[self fetchMostRecentQuantitySampleOfType:leanBodyMassType predicate:nil completion:^(HKQuantity *mostRecentQuantity, NSDate *startDate, NSDate *endDate, NSError *error) {
if (!mostRecentQuantity) {
NSLog(@"Either an error occured fetching the user's LeanBodyMass 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 LeanBodyMass information or none has been stored yet. In your app, try to handle this gracefully.", nil, nil)]);
}
else {
HKUnit *weightUnit = [HKUnit poundUnit];
double leanBodyMass = [mostRecentQuantity doubleValueForUnit:weightUnit];
callback(@[[NSNull null], @(leanBodyMass)]);
}
}];
}
@end @end
...@@ -39,16 +39,39 @@ RCT_EXPORT_METHOD(saveWeight:(NSDictionary *)input callback:(RCTResponseSenderBl ...@@ -39,16 +39,39 @@ RCT_EXPORT_METHOD(saveWeight:(NSDictionary *)input callback:(RCTResponseSenderBl
[self body_saveWeight:input callback:callback]; [self body_saveWeight:input callback:callback];
} }
RCT_EXPORT_METHOD(getMostRecentHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self body_getMostRecentHeight: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];
} }
RCT_EXPORT_METHOD(getMostRecentBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self body_getMostRecentBodyFatPercentage:input callback:callback];
}
RCT_EXPORT_METHOD(getMostRecentLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self body_getMostRecentLeanBodyMass:input callback:callback];
}
RCT_EXPORT_METHOD(getStepCountForToday:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) RCT_EXPORT_METHOD(getStepCountForToday:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{ {
[self fitness_getStepCountForToday:input callback:callback]; [self fitness_getStepCountForToday: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];
...@@ -94,7 +117,7 @@ RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock ...@@ -94,7 +117,7 @@ RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock
// make sure at least 1 read or write permission is provided // make sure at least 1 read or write permission is provided
if(!writeDataTypes && !readDataTypes){ if(!writeDataTypes && !readDataTypes){
callback(@[RCTMakeError(@"at least 1 write or read permission must be set in options.permissions", nil, nil)]); callback(@[RCTMakeError(@"at least 1 read or write permission must be set in options.permissions", nil, nil)]);
return; return;
} }
......
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