1

I'm writing an app that amongst other things, reads weight samples from HealthKit.
I'm also writing samples.
I'm trying to read the latest sample that isn't mine:

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) {  ... };

But I'm getting my own samples if they are the latest samples.
Any idea?

Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
Moshe Gottlieb
  • 3,963
  • 25
  • 41

1 Answers1

1

The way you have constructed the non_fdct predicate is not quite correct. Try this instead:

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

Allan
  • 7,039
  • 1
  • 16
  • 26
  • If that's true than I totally missed the way these predicates should work.. I'm currently filtering by my bundle ID, will comment / accept this once I test it, 10x! – Moshe Gottlieb Nov 26 '14 at 13:13