HKSampleQuery产生意外结果

时间:2019-10-02 10:24:38

标签: ios swift healthkit

我正在尝试使用.bodyMass和以下查询代码从HealthKit获取private let healthType = HKObjectType.quantityType(forIdentifier: .bodyMass)!的所有记录:

let mostRecentPredicate = HKQuery.predicateForSamples(
            withStart: Date(timeIntervalSince1970: 1546300800000),
            end: Date(),
            options: .strictEndDate
)

let sortDescriptor = NSSortDescriptor(key: HKSampleSortIdentifierStartDate, ascending: false)

let query = HKSampleQuery(
           sampleType: healthType,
           predicate: mostRecentPredicate,
           limit: 20, 
           sortDescriptors: [sortDescriptor]
) { (query, results, error) in
    guard let quantityResults = results as? [HKQuantitySample] else {
       completion(nil) 
    }

    // quantityResults will be an empty array, with 0 values.

    // some more irrelevant code for now
}

healthStore.execute(query)

但是,我在results的回调函数中收到一个18235 values数组,其中在Health应用程序中,我只有20。此外,当我尝试将结果转换为{{1} },没有任何值了。我使用的框架是否错误,还是有其他原因?

更多上下文:我正在使用WatchKit应用在WatchKit扩展中运行此代码。

0 个答案:

没有答案
相关问题