Im trying to create a Ti.Healthkit.StatisticsCollection where I can fetch number of steps taken, grouped per day. The thing is that I also need all sources, so I can filter ("manually") all steps added through Apple Health (manually) and other sources than the device and apple watch.
So; I've set up the Statistics query, everything looks fine. I can fetch all sources for each date. BUT, here's the thing, I can't no matter what, get the number of steps taken, per source.
var query = HealthKit.createStatisticsCollectionQuery(
{
type : HealthKit.OBJECT_TYPE_STEP_COUNT,
filter : HealthKit.createFilterForSamples(
{
startDate : date_from,
endDate : date_to
}),
options : HealthKit.STATISTICS_OPTION_CUMULATIVE_SUM | HealthKit.STATISTICS_OPTION_SEPARATE_BY_SOURCE,
anchorDate : anchorDate,
interval : 3600*24, // 24 hours
onInitialResults : function(e)
{
if (e.errorCode !== undefined)
{
//Utils.showError(e);
}
else
{
for(var i in e.statisticsCollection.statistics)
{
var statistics = e.statisticsCollection.statistics[i];
console.log(statistics.sources[0]);
var quantity = statistics.getSumQuantityForSource(statistics.sources[0]);
var stepCount = quantity.valueForUnit(HealthKit.createUnit('count'));
console.log(statistics.sources);
//console.log(statistics.startDate);
console.log(stepCount);
for(var k in statistics.sources)
{
var _source = statistics.sources[k];
var quantity = statistics.getSumQuantity(_source);
console.log(_source);
console.log(quantity);
I have tried to follow the Apple docs as well as the Ti.HealthKit docs, and as far as I can see I've tried everything now. I've also tried to fetch the steps while I iterate all sources, to put it inside the statistics method;
sumQuantityForSource(_source)
but that only retus "null".
I can get the number of steps for a day, but it contains all sources steps..
Does anyone have any suggestion what to try? I feel like I've tried everything possible.
