Hi All,
I am posting this to get some help on fetching Water intake data from Health Kit.
I have done (following a similar approach, and perfectly working) the fetch of the user weight, but for the water, somehow, I always receive back 0 samples.
I went to the Health App, added few entries (in different days) for the water intake, under the food sections.
Then, I use the following snippet to read the values, but I always have 0 values back.
What I am doing wrong?
let type = HKQuantityType(.dietaryWater)
let samplePredicate = HKSamplePredicate.sample(type: type, predicate: nil)
// Create the descriptor.
let descriptor = HKSampleQueryDescriptor(
predicates: [samplePredicate],
sortDescriptors: [SortDescriptor(\.endDate, order: .reverse)])
let results = try await descriptor.result(for: hkHealthStore)
The results
variable is always 0 elements.
What I am doing wrong?
PS: The permissions are checked and correctly given for this: HKQuantityType(.dietaryWater)