diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m index 5a29a898da44d06d0639cd6b7182dbb6801fa1b3..34fd328837a07105f0872461669cc942ab2c3531 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 0fccb76b6ffb67b595dd542f632ffa93cccbf00f..60faf2d9b949263e5803930684deefb1b62bd8d9 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m @@ -156,7 +156,8 @@ } NSDictionary *elem = @{ - @"activityName" : [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 0a385f8afe85979246b146061e6cafbba626e510..b5e2e20f773668c73718bddbb1f054a18e11e2bd 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,12 @@ AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) => ``` ## Changelog +0.6.5v +- Enable fetching basal energy [#23](https://github.com/terrillo/rn-apple-healthkit/pull/23) +- remove checkPermission functions in order to use from PR [#69](https://github.com/terrillo/rn-apple-healthkit/pull/69) +- Added correct link to permissions. [#73](https://github.com/terrillo/rn-apple-healthkit/pull/73) +- Add unified way to get workouts + convert Activity Types to name + isTracked flag [#25](https://github.com/terrillo/rn-apple-healthkit/pull/25) + 0.6.4v - Basal energy ([#23](https://github.com/terrillo/rn-apple-healthkit/pull/23)) - Fixed issues with saving weight in the past @@ -95,44 +101,46 @@ AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) => ## Wiki * [Installation](/docs/Install) * [Documentation](#documentation) - * [Permissions](#permissions) + * [Permissions](#supported-apple-permissions) * [Units](#units) * Base Methods * [isAvailable](/docs/isAvailable().md) * [initHealthKit](/docs/initHealthKit().md) * Realtime Methods * [initStepCountObserver](/docs/initStepCountObserver().md) + * [setObserver](/docs/setObserver().md) * Read Methods * [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 new file mode 100644 index 0000000000000000000000000000000000000000..a4c6cc680f9c5ab362c31726d09453f992c39b37 --- /dev/null +++ b/docs/getSamples().md @@ -0,0 +1,52 @@ +Query to get all activities of given type with extended information about it. + +```javascript 1.7 +let options = { + startDate: (new Date(2016,4,27)).toISOString(), + endDate: (new Date()).toISOString(), + type: 'Walking', // one of: ['Walking', 'StairClimbing', 'Running', 'Cycling', 'Workout'] +}; +``` + +The callback function will be called with a `samples` array containing objects with *value*, *startDate*, and *endDate* fields + +```javascript 1.7 +AppleHealthKit.getSamples(options, (err: Object, results: Array) => { + if (err) { + return; + } + console.log(results) +}); +``` + +Resulting object has different fields for different types. +In case of workout: +``` +{ + 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] + sourceId: String, // [[[sample sourceRevision] source] bundleIdentifier] + device: String, // [[sample sourceRevision] productType] or 'iPhone' + distance: Number, // [[sample totalDistance] doubleValueForUnit:[HKUnit mileUnit]] + start: String, // [RCTAppleHealthKit buildISO8601StringFromDate:sample.startDate]; + end: String, // [RCTAppleHealthKit buildISO8601StringFromDate:sample.endDate]; +} +``` +for other types: +``` +{ + tracked: Boolean, // [[sample metadata][HKMetadataKeyWasUserEntered] intValue] !== 1 + sourceName: String, // [[[sample sourceRevision] source] name] + sourceId: String, // [[[sample sourceRevision] source] bundleIdentifier] + device: String, // [[sample sourceRevision] productType] or 'iPhone' + start: String, // [RCTAppleHealthKit buildISO8601StringFromDate:sample.startDate]; + end: String, // [RCTAppleHealthKit buildISO8601StringFromDate:sample.endDate]; + + //based on required type, one of the following will be present. + distance: Number, // [[sample totalDistance] doubleValueForUnit:[HKUnit mileUnit]] + calories: Number, // [[sample totalEnergyBurned] doubleValueForUnit:[HKUnit kilocalorieUnit]] +} +``` diff --git a/docs/setObserver().md b/docs/setObserver().md new file mode 100644 index 0000000000000000000000000000000000000000..8f551613ca62dbf830ec32997dbeef3df68f3649 --- /dev/null +++ b/docs/setObserver().md @@ -0,0 +1,15 @@ +Will listen for any updates in a given type data in healthKit and call app. + +type - one of the `['Walking', 'StairClimbing', 'Running', 'Cycling', 'Workout']` +```javascript 1.8 +import { NativeAppEventEmitter } from 'react-native'; +//...// +AppleHealthKit.setObserver({ type: 'Walking' }); +NativeAppEventEmitter.addListener( + 'observer', + callback + ); +``` + +So, callback would be call when new data of given type appears. When it happens, in order to get new info +need to call getSamples() function with proper arguments. diff --git a/package.json b/package.json index 39bcf851edb858e24784b5704652f865c13031c0..f6027689d5033f2bd199e5920e7b0905923ecebb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rn-apple-healthkit", - "version": "0.6.4", + "version": "0.6.5", "description": "A React Native package for interacting with Apple HealthKit", "main": "index.js", "repository": {