Commit 1a1c4c71 authored by Greg Wilson's avatar Greg Wilson

added getWeightSamples and getHeightSamples to Methods_Body category

parent 9dd3d74e
...@@ -11,15 +11,16 @@ ...@@ -11,15 +11,16 @@
@interface RCTAppleHealthKit (Methods_Body) @interface RCTAppleHealthKit (Methods_Body)
- (void)body_getCurrentWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)body_getCurrentWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getWeightSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_saveWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)body_saveWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getLatestBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)body_getLatestBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_saveBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)body_saveBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getMostRecentHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)body_getMostRecentHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getHeightSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_saveHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)body_saveHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getMostRecentBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)body_getMostRecentBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getMostRecentLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)body_getMostRecentLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
......
...@@ -37,16 +37,46 @@ ...@@ -37,16 +37,46 @@
} }
- (void)body_getWeightSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass];
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:weightType
unit:unit
predicate:predicate
ascending:ascending
limit:limit
completion:^(NSArray *results, NSError *error) {
if(results){
callback(@[[NSNull null], results]);
return;
} else {
NSLog(@"error getting weight samples: %@", error);
callback(@[RCTMakeError(@"error getting weight samples", nil, nil)]);
return;
}
}];
}
- (void)body_saveWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)body_saveWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
// double weight= [[input objectForKey:@"weight"] doubleValue];
double weight = [RCTAppleHealthKit doubleValueFromOptions:input]; double weight = [RCTAppleHealthKit doubleValueFromOptions:input];
NSDate *sampleDate = [RCTAppleHealthKit dateFromOptionsDefaultNow:input]; NSDate *sampleDate = [RCTAppleHealthKit dateFromOptionsDefaultNow:input];
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit poundUnit]];
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input];
if(unit == nil){
unit = [HKUnit poundUnit];
}
HKQuantity *weightQuantity = [HKQuantity quantityWithUnit:unit doubleValue:weight]; HKQuantity *weightQuantity = [HKQuantity quantityWithUnit:unit doubleValue:weight];
HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass]; HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass];
...@@ -136,6 +166,41 @@ ...@@ -136,6 +166,41 @@
} }
- (void)body_getHeightSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKQuantityType *heightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight];
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit inchUnit]];
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:heightType
unit:unit
predicate:predicate
ascending:ascending
limit:limit
completion:^(NSArray *results, NSError *error) {
if(results){
callback(@[[NSNull null], results]);
return;
} else {
NSLog(@"error getting height samples: %@", error);
callback(@[RCTMakeError(@"error getting height samples", nil, nil)]);
return;
}
}];
}
- (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];
......
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