HKSourceQuery not returning values when using with predicateForWorkouts

216 Views Asked by At

I am trying to load all sources for cycling workouts. For this, I am using a HKSourceQuery like in the following code block:

let workoutPredicate = HKQuery.predicateForWorkouts(with: .cycling)
let query = HKSourceQuery(sampleType: .workoutType(), samplePredicate: workoutPredicate) { (query, samples, error) in
    // print(samples, error) prints nil, nil
}

However, unexpectedly, bot error and samples are nil. There exist cycling workouts in the health store, both from my own app and from an Apple Watch. Passing samplePredicate: nil returns sources. Passing samplePredicate: sourcePredicate with let sourcePredicate = HKQuery.predicateForObjects(from: .default()) works. Only querying for all cycling workouts does not work.

How do I load all sources for cycling workouts from HealthKit?

0

There are 0 best solutions below