HealthKit's HKAnchoredObjectQuery is not returning deleted objects in iOS 9.0. Even if i delete a object and then add a object the deleted objects array is always empty (except on the first launch of app).
But the same code works fine with iOS 9.2.1. The deleted objects are returned whenever a object is added to health app and observer query is fired.
Is this some new update in iOS 9.2.1 and the bug with deleted objects is resolved in this version?
I could not find any Apple documentation confirming this.
Edit: The code firing the query is
NSPredicate* predicate = [HKQuery predicateForSamplesWithStartDate: [NSDate dateWithTimeIntervalSinceNow:-172800.0] endDate:nil options:0];
HKAnchoredObjectQuery *query =
[[HKAnchoredObjectQuery alloc]
initWithType:sampleType
predicate:predicate
anchor:anchor
limit:HKObjectQueryNoLimit
resultsHandler:^(HKAnchoredObjectQuery * _Nonnull query,
NSArray<__kindof HKSample *> * _Nullable sampleObjects,
NSArray<HKDeletedObject *> * _Nullable deletedObjects,
HKQueryAnchor * _Nullable newAnchor,
NSError * _Nullable error) {
}];
This is a bug was a bug in iOS 9.0 that was fixed in 9.1. You can work around the issue by not specifying a predicate that constrains on the
startDate
orendDate
ofHKSample
.