I'm rewriting my workout app on Apple Watch to use the new HKWorkoutBuilder. Everything appears straight forward but can't seam to be able to access the calories burned in my HKLiveWorkoutBuilderDelegate to update my UI.
func workoutBuilder(_ workoutBuilder: HKLiveWorkoutBuilder, didCollectDataOf collectedTypes: Set<HKSampleType>) {
let caloriesType = HKQuantityType.quantityType(forIdentifier: .activeEnergyBurned)!
if collectedTypes.contains(caloriesType) {
if let updatedStatistics = workoutBuilder.statistics(for: caloriesType) {
if let quantity = updatedStatistics.mostRecentQuantity() {
// Code never gets to here!?
}
}
}
}
The updateStatistics is valid. It just the updateStatistics.mostRecentQuatity() that doesn't return a value.
These are the types my HKLiveWorkoutDataSource is collecting:
- 0 : HKQuantityTypeIdentifierHeartRate
- 1 : HKQuantityTypeIdentifierActiveEnergyBurned
- 2 : HKQuantityTypeIdentifierBasalEnergyBurned
Any ideas!?