Run/Walk workout. Need activeEnergy, distance walked immediately

I have an iPhone 6 which has delayed collection of active energy b urned anddistance walked data.

I am creating an app that Maps the user's walk or run. Consequently, I need data of energy burned and distance walked when the user starts the walk/run workout.

Currently, the active energy burned distance walked shows 0 even after 4000+ steps are taken and is usually not obtained until the end of the day.

Is there a way I can get this data immediately and thus associate it with the workout?

Note: steps data is almost immediately updated.
I have planned to use the HKWorkout class for this but if iOS doesnt return the activeEnergy count immediately after the workout its useless.

Can someone please guide me on this one?
Active Energy is only available on watchOS; iOS devices do not compute active energy during workouts. In addition, HKWorkoutSession and HKLiveWorkoutBuilder are only available on watchOS.

To track a workout on iOS, you'll need to use HKAnchoredObjectQuery to monitor for new samples being generated and saved. If your app is the in the foreground, this will cause samples to be saved at a more frequent cadence, and you can use that to track the steps taken or distance walked during the workout.
Hi Frameworks Engineer,

I have made a predicate that queries for health data for the start and end time of workout. Then I start an observer query for the same predicate. When I get a result, how do I co-relate it to the workout sample?

Example, person walks from 7am to 7.20 am. My predicate sets 7 am of the same day as start date and 7.20 pm as end date. Now I run an observer query with this timings. When I get the result I want to associate it with the corresponding workout sample. If we assume the user takes a walk or a run just once it is easy but he might do it twice a day and associating it with a sample that is returned at the end of the day after both workouts are over seems like a puzzle.

So... Saving the workout starts an observer query for 3 types of health kit samples. When the observer is called, i get the results for the given predicate. Now how do i associate it with the workout object.

FYI, I am Not using HKWorkout object for now. I have a coredata entity that saves my workout info.

I was thinking of checking out the times of the first and the last object in the results to see if they are within the time period of any workout (which hasnt been flagged as update) and then updating and saving the sample to the workout. I think i can do this even with an hkworkout object.

Can u pls guide me?
Run/Walk workout. Need activeEnergy, distance walked immediately
 
 
Q