【问题标题】:Exclude own samples from healthkit queries从 healthkit 查询中排除自己的样本
【发布时间】:2014-11-16 16:58:39
【问题描述】:

我正在编写一个应用程序,其中包括从 HealthKit 读取体重样本。
我也在写示例。
我正在尝试阅读不属于我的最新示例:

NSPredicate* non_fdct = [NSCompoundPredicate notPredicateWithSubpredicate:[HKQuery predicateForObjectsFromSource:[HKSource defaultSource]]];
NSSortDescriptor *last = [[NSSortDescriptor alloc] initWithKey:HKSampleSortIdentifierEndDate ascending:NO];
HKSampleQuery* query = [[HKSampleQuery alloc] initWithSampleType:[HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass] predicate:non_fdct limit:1 sortDescriptors:@[last] resultsHandler:^(HKSampleQuery *query, NSArray *results, NSError *error) {  ... };

但是,如果它们是最新的样品,我会得到自己的样品。
有什么想法吗?

【问题讨论】:

    标签: ios objective-c healthkit hksamplequery


    【解决方案1】:

    您构造non_fdct 谓词的方式并不完全正确。试试这个:

    NSPredicate *non_fdct = [NSPredicate predicateFromString:@"%K != %@", HKPredicateKeyPathSource, [HKSource defaultSource]];

    【讨论】:

    • 如果这是真的,那么我完全错过了这些谓词的工作方式。我目前正在按我的包 ID 过滤,一旦我测试它就会评论/接受它,10x!
    猜你喜欢
    • 1970-01-01
    • 2022-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-10
    • 1970-01-01
    相关资源
    最近更新 更多