Reputation: 41
Hope this question doesn't sound too silly, but I haven't been able to find a solution yet. I'm currently writing an app using Xamarin that integrates with HealthKit. Data stored in HK is periodically synced to a server. This is done through an HKAnchoredObjectQuery that pulls Food Correlations.
Since the Data is pulled periodically there is the scenario that between syncs, a user might delete a value in HealthKit. That delete needs to be propagated back to the server on the next sync.
My initial thought was to do this with an Observer Query.
My Question is: Using an Observer Query for HealthKit, is there a way to determine if the action that triggered the query is a delete action?
public void CheckForDelete (Subject subject)
{
var sampleType = HKObjectType.GetCorrelationType (HKCorrelationTypeKey.IdentifierFood);
var predicate = HKQuery.GetPredicateForSamples (NSDate.DistantPast, NSDate.Now, HKQueryOptions.None);
var observerQuery = new HKObserverQuery (sampleType, predicate, (query, completion, error ) => {
//...Determine if action was a Delete
//Code to delete on backend
completion();
});
HealthKitStore.ExecuteQuery (observerQuery);
}
Upvotes: 4
Views: 379
Reputation: 7353
In iOS 9, HKAnchoredObjectQuery
has been modified to report deleted objects.
Upvotes: 1