私は健康アプリケーションを作っています。私はSwiftのwalkingRunningDistance
をHealthKit
にしたいと思っています。しかし、私には問題があります。戻り値は0.0mileです。速攻でHealthKitを使用して歩行と走行距離を取得する方法
なぜ戻り値が0マイルですか?
私のコードはこれです。
func recentSteps3(completion: (Double, NSError?) ->()){
let type = HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning)
let date = NSDate()
let cal = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
let newDate = cal.startOfDayForDate(date)
let predicate = HKQuery.predicateForSamplesWithStartDate(newDate, endDate: NSDate(), options: HKQueryOptions.StrictStartDate)
let query = HKSampleQuery(sampleType: type!, predicate: predicate, limit: HKObjectQueryNoLimit, sortDescriptors: nil) { query, results, error in
var distance: Double = 0
if results?.count > 0
{
for result in results as! [HKQuantitySample]
{
distance += result.quantity.doubleValueForUnit(HKUnit.mileUnit())
}
}
completion(distance, error)
}
healthAuth.healthStore.executeQuery(query)
}
を数える取得するためにアクセスし、メソッドの下をrequstingための上記の方法あなたは、この問題を解決しました。私は同じ問題があります。 – muhammedkasva