From 61a1e7c255201dc51b0690b348af7bc3bf4cf537 Mon Sep 17 00:00:00 2001 From: Evgeny Evstropov Date: Tue, 26 Feb 2019 20:03:07 +0100 Subject: [PATCH] change back default to imperial system, add activity name field, fix docs --- .../RCTAppleHealthKit+Methods_Body.m | 19 ++-------- RCTAppleHealthKit/RCTAppleHealthKit+Queries.m | 3 +- README.md | 38 +++++++++---------- docs/getSamples().md | 4 +- 4 files changed, 27 insertions(+), 37 deletions(-) diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m index 5a29a89..34fd328 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m @@ -18,11 +18,8 @@ { HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass]; - HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit gramUnitWithMetricPrefix:HKMetricPrefixKilo]]; - if(unit == nil){ - unit = [HKUnit gramUnit]; - } - + HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit poundUnit]]; + [self fetchMostRecentQuantitySampleOfType:weightType predicate:nil completion:^(HKQuantity *mostRecentQuantity, NSDate *startDate, NSDate *endDate, NSError *error) { @@ -151,11 +148,7 @@ - (void)body_getLatestHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { HKQuantityType *heightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight]; - - HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit meterUnitWithMetricPrefix:HKMetricPrefixCenti]];; - if(unit == nil){ - unit = [HKUnit meterUnit]; - } + HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit inchUnit]];; [self fetchMostRecentQuantitySampleOfType:heightType predicate:nil @@ -217,11 +210,7 @@ { double height = [RCTAppleHealthKit doubleValueFromOptions:input]; NSDate *sampleDate = [RCTAppleHealthKit dateFromOptionsDefaultNow:input]; - - HKUnit *heightUnit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit inchUnit]];; - if(heightUnit == nil){ - heightUnit = [HKUnit inchUnit]; - } + HKUnit *heightUnit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit inchUnit]]; HKQuantity *heightQuantity = [HKQuantity quantityWithUnit:heightUnit doubleValue:height]; HKQuantityType *heightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight]; diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m index fdbaea3..f18ceb3 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m @@ -156,7 +156,8 @@ } NSDictionary *elem = @{ - @"activityNameId" : [NSNumber numberWithInt:[sample workoutActivityType]], + @"activityId" : [NSNumber numberWithInt:[sample workoutActivityType]], + @"activityName" : type, @"calories" : @(energy), @"tracked" : @(isTracked), @"sourceName" : [[[sample sourceRevision] source] name], diff --git a/README.md b/README.md index 6c29d92..409d745 100644 --- a/README.md +++ b/README.md @@ -108,34 +108,34 @@ AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) => * [getActiveEnergyBurned](/docs/getActiveEnergyBurned().md) * [getBasalEnergyBurned](/docs/getBasalEnergyBurned().md) * [getBiologicalSex](/docs/getBiologicalSex().md) - * [getBloodGlucoseSamples](/docs/getbloodglucosesamples().md) - * [getBloodPressureSamples](/docs/getbloodpressuresamples().md) - * [getBodyTemperatureSamples](/docs/getbodytemperaturesamples().md) - * [getDailyDistanceCyclingSamples]() + * [getBloodGlucoseSamples](/docs/getBloodglucoseSamples().md) + * [getBloodPressureSamples](/docs/getBloodPressureSamples().md) + * [getBodyTemperatureSamples](/docs/getBodyTemperatureSamples().md) + * [getDailyDistanceCyclingSamples](/docs/getDailyDistanceCyclingSamples().md) * [getDailyDistanceWalkingRunningSamples](/docs/getDailyDistanceWalkingRunningSamples().md) * [getDailyFlightsClimbedSamples](/docs/getDailyFlightsClimbedSamples().md) * [getDailyStepCountSamples](/docs/getDailyStepCountSamples().md) * [getDateOfBirth](/docs/getDateOfBirth().md) - * [getDistanceCycling](/docs/getdistancecycling().md) + * [getDistanceCycling](/docs/getDistanceCycling().md) * [getDistanceWalkingRunning](/docs/getDistanceWalkingRunning().md) - * [getFlightsClimbed](/docs/getflightsclimbed().md) - * [getHeartRateSamples](/docs/getheartratesamples().md) - * [getHeightSamples](/docs/getheightsamples().md) - * [getLatestBmi](/docs/getlatestbmi().md) - * [getLatestBodyFatPercentage](/docs/getlatestbodyfatpercentage().md) - * [getLatestHeight](/docs/getlatestheight().md) - * [getLatestLeanBodyMass](/docs/getlatestleanbodymass().md) - * [getLatestWeight](/docs/getlatestweight().md) - * [getRespiratoryRateSamples](/docs/getrespiratoryratesamples().md) - * [getSleepSamples](/docs/getsleepsamples().md) + * [getFlightsClimbed](/docs/getFlightsClimbed().md) + * [getHeartRateSamples](/docs/getHeartRateSamples().md) + * [getHeightSamples](/docs/getHeightSamples().md) + * [getLatestBmi](/docs/getLatestBmi().md) + * [getLatestBodyFatPercentage](/docs/getLatestBodyFatPercentage().md) + * [getLatestHeight](/docs/getLatestHeight().md) + * [getLatestLeanBodyMass](/docs/getLatestLeanBodyMass().md) + * [getLatestWeight](/docs/getLatestWeight().md) + * [getRespiratoryRateSamples](/docs/getRespiratoryRateSamples().md) + * [getSleepSamples](/docs/getSleepSamples().md) * [getStepCount](/docs/getStepCount().md) - * [getWeightSamples](/docs/getweightsamples().md) + * [getWeightSamples](/docs/getWeightSamples().md) * [getSamples](docs/getSamples().md) * Write Methods - * [saveBmi](/docs/savebmi().md) - * [saveHeight](/docs/saveheight().md) + * [saveBmi](/docs/saveBmi().md) + * [saveHeight](/docs/saveHeight().md) * [saveMindfulSession](/docs/saveMindfulSession().md) - * [saveWeight](/docs/saveweight().md) + * [saveWeight](/docs/saveWeight().md) * [saveSteps](/docs/saveSteps().md) * [References](#references) diff --git a/docs/getSamples().md b/docs/getSamples().md index 8d7f651..a4c6cc6 100644 --- a/docs/getSamples().md +++ b/docs/getSamples().md @@ -23,7 +23,8 @@ Resulting object has different fields for different types. In case of workout: ``` { - activityNameId: Number, // [NSNumber numberWithInt:[sample workoutActivityType]] + activityId: Number, // [NSNumber numberWithInt:[sample workoutActivityType]] + activityName: Number, // [RCTAppleHealthKit stringForHKWorkoutActivityType:[sample workoutActivityType]] calories: Number, // [[sample totalEnergyBurned] doubleValueForUnit:[HKUnit kilocalorieUnit]] tracked: Boolean, // [[sample metadata][HKMetadataKeyWasUserEntered] intValue] !== 1 sourceName: String, // [[[sample sourceRevision] source] name] @@ -37,7 +38,6 @@ In case of workout: for other types: ``` { - activityNameId: Number, // [NSNumber numberWithInt:[sample workoutActivityType]] tracked: Boolean, // [[sample metadata][HKMetadataKeyWasUserEntered] intValue] !== 1 sourceName: String, // [[[sample sourceRevision] source] name] sourceId: String, // [[[sample sourceRevision] source] bundleIdentifier] -- 2.26.2