getSamples().md 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
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<Object>) => {
  if (err) {
    return;
  }
  console.log(results)
});
```

Resulting object has different fields for different types. 
In case of workout:
```
{
26 27
  activityId: Number, // [NSNumber numberWithInt:[sample workoutActivityType]]
  activityName: Number, // [RCTAppleHealthKit stringForHKWorkoutActivityType:[sample workoutActivityType]]
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
  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]]
}
```