I'm using health kit to get blood pressure from Health App,I have a strange behavior : I add a new data from health app, it appears correctly on my client app, When I remove that data from health app using Delete All action, my client App still return it. But when I delete that same data separately (swipe left on the cell and click the Delete button),my client App doesn't return the data. The correct behavior that I'm looking for is when there is no data on health App, my client App should show also no data.
This is my code :
[self.healthStore requestAuthorizationToShareTypes:nil readTypes:[self dataTypesToRead] completion:^(BOOL success, NSError *error) {
if (success) {
HKSampleType *sampleType = [HKSampleType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodPressureSystolic];
NSPredicate *predicate = [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionNone];
HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:sampleType predicate:predicate limit:0 sortDescriptors:nil resultsHandler:^(HKSampleQuery *query, NSArray *results, NSError *error) {
if (!results) {
NSLog(@"An error occured. The error was: %@.", error);
abort();
}
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"results: %@.", results);
});
}];
[self.healthStore executeQuery:query];
}
}];
This seems like a bug in iOS, not something you can solve by changing your app's code. You should file a radar with Apple.