【问题标题】:HealthKit search Samples by "Date Added to Health"HealthKit 按“添加到健康的日期”搜索样本
【发布时间】:2016-01-26 10:13:49
【问题描述】:

有没有办法从 HealthKit 中获取按“添加到健康的日期”过滤的样本?我想获取比我上次搜索它们的“添加到健康的日期”-Date 更新的每个样本。

我只知道搜索“开始日期”和“结束日期”的方法,但有可能有人添加了过去的样本 (example screenshot)。

// Predicate to search by "Start Date" and "End Date"
let predicate = HKQuery.predicateForSamplesWithStartDate(fromDate, endDate: toDate, options: .None)

【问题讨论】:

    标签: swift healthkit


    【解决方案1】:

    听起来您想使用HKAnchoredObjectQuery。第一次进行此查询时,传入一个 nil 锚。当你得到你的结果时,你将返回的锚点存储在某个地方(NSUserDefaults、CoreData 等)。下次您进行查询时,传入您保存的锚点而不是 nil,这将返回自生成锚点以来输入到 HealthKit 并且与查询的谓词匹配的所有项目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-15
      • 2022-06-13
      • 2020-09-19
      • 2022-01-06
      • 1970-01-01
      相关资源
      最近更新 更多