Reputation: 1733
While I am trying to delete some records I previously saved in HealthKit, I got an error if I use -deleteObjectsOfType:predicate:withCompletion:
. The error says:
Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.apple.healthd.server" UserInfo={NSDebugDescription=connection to service named com.apple.healthd.server}
But if I first query the records using the same type and predicate, and then delete the returned samples with -deleteObjects:withCompletion:
. It works.
Here's the type and predicate if it helps:
HKCategoryType *type = [HKCategoryType categoryTypeForIdentifier:HKCategoryTypeIdentifierMenstrualFlow];
NSPredicate *predicate = [HKQuery predicateForObjectsFromSource:[HKSource defaultSource]];
Anyone had the same issue? Thanks.
Upvotes: 2
Views: 575
Reputation: 7363
This is a known issue with deleteObjectsOfType:predicate:withCompletion:
when using some predicates (including the one you've specified). The workaround you describe is appropriate. And as I mentioned in the comments, you should file a bug with Apple.
However, note that the specifying the predicate [HKQuery predicateForObjectsFromSource:[HKSource defaultSource]]
when deleting objects is unnecessary. Your app can only delete its own samples, so it is redundant to provide a predicate that matches samples from the default source.
Upvotes: 1