【问题标题】:Ignore manual entries from Apple Health app as Data Source忽略来自 Apple Health 应用程序的手动输入作为数据源
【发布时间】:2015-07-02 12:23:41
【问题描述】:

您好,我正在编写一个从 Apples Health 应用程序获取数据的健身应用程序。

到目前为止一切顺利。

问题:在健康应用程序中,可以手动输入数据,这使得作弊成为可能。

问题:如何排除或忽略此特定数据条目。

只有“来源:健康”的数据,所以我仍然可以从随机的健身追踪器中读取数据。

【问题讨论】:

  • 您基本上可以使用 HKQuery 将搜索限制在某些应用程序上,在 HKQuery + (NSPredicate *)predicateForObjectsFromSource:(HKSource *)source; 上查看此方法;

标签: ios healthkit


【解决方案1】:

用户手动输入的 HealthKit 中的样本将具有 HKMetadataKeyWasUserEntered 元数据键的 YES 值。要创建仅匹配非用户输入的样本的谓词,您可以使用以下命令:

[NSPredicate predicateWithFormat:@"metadata.%K != YES", HKMetadataKeyWasUserEntered];

请注意,这必须表述为value != YES,因为键的值可以是YES、NO 或nil,nil 表示NO。

【讨论】:

    【解决方案2】:

    斯威夫特 4:

    let predicate = NSPredicate(format: "metadata.%K != YES", HKMetadataKeyWasUserEntered)
    

    如果你有两个谓词,使用CompoundPredicate:

    let compoundPredicate = NSCompoundPredicate(type: .and, subpredicates: [predicate1, predicate2])
    

    【讨论】:

    • 谢谢.. 节省了我的时间 :) +1
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-29
    • 1970-01-01
    • 2017-10-09
    • 2017-02-08
    • 2016-02-09
    相关资源
    最近更新 更多