diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m index 11ea768c775a9c14fe9c245ca2bd8d0eda7d10a5..fdbaea39123f07781746f9b08759ab804197954d 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Queries.m @@ -156,7 +156,7 @@ } NSDictionary *elem = @{ - @"activityName" : [NSNumber numberWithInt:[sample workoutActivityType]], + @"activityNameId" : [NSNumber numberWithInt:[sample workoutActivityType]], @"calories" : @(energy), @"tracked" : @(isTracked), @"sourceName" : [[[sample sourceRevision] source] name], diff --git a/README.md b/README.md index 0a385f8afe85979246b146061e6cafbba626e510..9a402e8c1b93d5955b61a765dc8afabe9f5fbf17 100644 --- a/README.md +++ b/README.md @@ -100,8 +100,10 @@ AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) => * Base Methods * [isAvailable](/docs/isAvailable().md) * [initHealthKit](/docs/initHealthKit().md) + * checkSharePermission * Realtime Methods * [initStepCountObserver](/docs/initStepCountObserver().md) + * [setObserverForType](/docs/setObserverForType().md) * Read Methods * [getActiveEnergyBurned](/docs/getActiveEnergyBurned().md) * [getBasalEnergyBurned](/docs/getBasalEnergyBurned().md) @@ -128,6 +130,7 @@ AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) => * [getSleepSamples](/docs/getsleepsamples().md) * [getStepCount](/docs/getStepCount().md) * [getWeightSamples](/docs/getweightsamples().md) + * [getSamples](docs/getSamples().md) * Write Methods * [saveBmi](/docs/savebmi().md) * [saveHeight](/docs/saveheight().md) diff --git a/docs/getSamples().md b/docs/getSamples().md new file mode 100644 index 0000000000000000000000000000000000000000..8d7f65104503b7811585d848a5ddf71c1be375c4 --- /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: +``` +{ + activityNameId: Number, // [NSNumber numberWithInt:[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: +``` +{ + 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] + 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/setObserverForType().md b/docs/setObserverForType().md new file mode 100644 index 0000000000000000000000000000000000000000..8f551613ca62dbf830ec32997dbeef3df68f3649 --- /dev/null +++ b/docs/setObserverForType().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.