2016-03-31 4 views
0

Ti.Healthkit.StatisticsCollectionを作成しようとしていますが、1日にグループ化された手順の数を取得できます。問題は、私もすべてのソースが必要なため、Apple Health(手動)やデバイスやApple Watch以外のソースから追​​加したすべてのステップをフィルタリング(「手動」)できます。Titanium HealthKit Module - 累積および統計別にソース別にクエリを作成する

So;私は統計情報のクエリを設定して、すべてがうまく見えます。私は日付ごとにすべてのソースを取得できます。しかし、ここには、私は何があっても、ソースごとに取られたステップの数を取得することはできません。

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); 

私は、Appleのドキュメントだけでなく、Ti.HealthKitドキュメントに従うことを試みていると、私の知る限り、私は今、すべてを試してみました。私はすべてのソースを反復しながら、統計メソッドの中に入れるためにステップをフェッチしようとしました。

sumQuantityForSource(_source)

しかし、それは唯一の "ヌル" を返します。

誰が何をしようとする任意の提案を持っていますか?..私はその日のためのステップ数を得ることができますが、それはすべてのソースの手順が含まれていますか私は可能な限りすべてを試したような気がします。

答えて

1

よく、私はこの記事の5時間10分後に私が間違ったことを見つけ出しました。私は "quantity"がnull(var quantity = statistics.getSumQuantity(_source);)であるかどうかをチェックして、次の反復を続行する必要があります。結果配列の下にステップがあるため、ソースにヒットします。

関連する問題