ios - HKSampleQuery 产生意外结果
问题描述
.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)
但是,我在 Health 应用程序results
的 where 回调中收到了一个数组18235 values
,我只有 20 个。此外,当我尝试将结果转换为 时HKQuantitySample
,不再有任何值。我使用的框架是错误的,还是其他原因?
更多上下文:我正在使用 WatchKit 应用程序在 WatchKit 扩展中运行此代码。
解决方案
推荐阅读
- java - 触发错误的 onErrorContinue 值中的 Project Reactor 为 null
- pandas - 将一列日期和时间转换为运行秒数
- string - Power BI - 在列中搜索值,返回 True/False
- logic - 加法器和减法器代码不起作用 VHDL
- c# - 如何转换带有错误土耳其字符的字符串以显示正确的字符?
- docker - 从本地另一个容器内连接到 dockerized REST JaxRS 端点
- sql - 使用 VB 脚本恢复 SQL .bak 文件?
- spring-boot - (如何)我可以在同一服务器和端口上运行多个 Spring Boot 应用程序吗?
- python - 梯形的中位数
- javascript - MongoDB $in 和 $ne