HKLiveWorkoutBuilderDelegate can't get calories

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!?

I'm having the same issue. The delegate method gets called, but the updatedStatistics doesn't have a value.


I'm testing using the simulator. I may go ahead an update my watch to the beta so I can try it out there.

I get the same behavior wether on simulater or on device. Just tested it with beta 4.

Found the answer. It looks like all I had to do was call updatedStatistics.sumQuantity(), instead of the mostRecentQuantity method I was calling.

HKLiveWorkoutBuilderDelegate can't get calories
 
 
Q