2
Ich habe diese Methode, um heute Schritte von HealthKit zu lesen.Lesen Schritte für Datumsintervalle von HealthKit mit Swift
func todaySteps(completion: (Double, NSError?) ->())
{ // this function gives you all of the steps the user has taken since the beginning of the current day.
let type = HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount) // The type of data we are requesting
let date = NSDate()
print(date)
let cal = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
let newDate = cal.startOfDayForDate(date)
print(newDate)
let predicate = HKQuery.predicateForSamplesWithStartDate(newDate, endDate: NSDate(), options: .None) // Our search predicate which will fetch all steps taken today
// The actual HealthKit Query which will fetch all of the steps and add them up for us.
let query = HKSampleQuery(sampleType: type!, predicate: predicate, limit: 0, sortDescriptors: nil) { query, results, error in
var steps: Double = 0
if results?.count > 0
{
for result in results as! [HKQuantitySample]
{
steps += result.quantity.doubleValueForUnit(HKUnit.countUnit())
}
}
completion(steps, error)
}
executeQuery(query)
}
können nun sagen, wenn ich total Schritte jeden Tag von 1/Juni/2016-7/Juni/2016
Wie kann ich lesen will, dass Sie mich bitte
Dank anleiten