Reputation: 299
I have HealthKit background delivery working with a HKObserverQuery and HKAnchoredObjectQuery set up in my AppDelegate as advised in the documentation. While I get callbacks for new data points quickly, I have noticed in my testing that if I make a modification to the Healthkit data that is JUST a deletion (no new HKSample points added), I do not get a callback until the next new point is added. At that point, I will get a callback for the new data point, plus the previous deletes. But I can never get a callback that contains just deletes.
The thing that has me worried is that Apple says that these HKDeletedObjects disappear and won't show up in any queries after some undetermined period of time.
So if my app is synchronizing data from HealthKit using this method, what happens in the case where the user deletes some data and then, for a long period of time, doesn't add any new points or launch my app to the foreground? I think that I would just miss the delete entirely in that case.
TLDR: Does the callback for an HKAnchoredObjectQuery ONLY get called in the case where there is at least one new HKSample (even if there are deletes available)? If so, how are we supposed to handle long periods of inactivity after a delete?
Upvotes: 1
Views: 889
Reputation: 193
To the first part of your question: As I read the documentation of HKStore.enableBackgroundDeliveryForType()... "HealthKit wakes your app whenever new samples of the specified type are saved to the store" - only new samples will trigger the query and this is consistent with my experience.
To the second part, setting HKAnchoredObjectQuery.updateHandler, is causing the anchored query to trigger upon deletes and adds. In my experience though, it is not consistent (see my related question).
Upvotes: 0