Example #1
0
    /*! @brief Fire off the appropriate HealthKit query.
     */
    public void ReadData()
    {
        // since this can take a while, especially on older devices, I use this to avoid firing off multiple concurrent requests.
        Debug.Log("read data...");
        if (!reading)
        {
            reading = true;

            DateTimeOffset now = DateTimeOffset.UtcNow;
            // for this example, we'll read everything from the past 24 hours
            DateTimeOffset start = now.AddDays(-1);

            double steps = 0;
            healthStore.ReadQuantitySamples(HKDataType.HKQuantityTypeIdentifierStepCount, start, now, delegate(List <QuantitySample> samplesW) {
                if (samplesW.Count > 0)
                {
                    foreach (QuantitySample sample in samplesW)
                    {
                        Debug.Log(String.Format(" - {0} from {1} to {2}", sample.quantity.doubleValue, sample.startDate, sample.endDate));
                        steps += sample.quantity.doubleValue;
                    }
                    resultsLabel.text = "steps:" + steps.ToString();
                }
                reading = false;
            });
        }
    }