I am stumped.
I have code that works perfectly on the iOS simulator but when I debug on an actual device the HKAnchoredObjectQuery object is inactive before it runs:
<HKAnchoredObjectQuery:0x2816e8780 inactive>
And then deactivated after it executes in the results handler:
<HKAnchoredObjectQuery:0x2816e8780 deactivated>
My code looks like this:
var query = new HKAnchoredObjectQuery(type, compoundPredicate, lastAnchor, nuint.MaxValue, new HKAnchoredObjectResultHandler2(
(q, results, anchor, error) =>
{
if (error != null)
{
_logger.Error("GetCountSinceLastAnchor: {description}", error.DebugDescription);
}
var totalCountInThisAnchor = results.Cast<HKQuantitySample>().Sum(sample => sample.Quantity.GetDoubleValue(unit));
_logger.Information("GetCountSinceLastAnchor: type:{type}, count: {count}, lastAnchor:{lastAnchor}, New Anchor:{anchor}", type.DebugDescription, totalCountInThisAnchor, lastAnchor, anchor);
taskCompletionSource.SetResult(Tuple.Create(totalCountInThisAnchor, anchor));
}));
_healthKitStore.ExecuteQuery(query);
So, a breakpoint at ExecuteQuery
gives me the "inactive" tag on the query
object and a breakpoint at if (error != null)
gives me "deactivated" on the q
.
Does anyone have any idea why this is happening? Like I said this all works great on the iOS Simulator.
Also, I know this is not a read permission problem because I have an HKSampleQuery
that returns results of the same type that I am querying for in the included code.