Commit aca094bf authored by Andrew Allen's avatar Andrew Allen

add saveLeanBodyMass

parent 08ea5bef
......@@ -26,5 +26,6 @@
- (void)body_saveBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_getLatestLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)body_saveLeanBodyMass:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
@end
......@@ -259,7 +259,6 @@
- (void)body_saveBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
double percentage = [RCTAppleHealthKit doubleValueFromOptions:input];
NSDate *sampleDate = [RCTAppleHealthKit dateFromOptionsDefaultNow:input];
HKUnit *unit = [HKUnit percentUnit];
......@@ -307,4 +306,25 @@
}];
}
- (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
......@@ -109,6 +109,11 @@ RCT_EXPORT_METHOD(getLatestLeanBodyMass:(NSDictionary *)input callback:(RCTRespo
[self body_getLatestLeanBodyMass: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)
{
[self fitness_getStepCountOnDay:input callback:callback];
......
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