Workout session [session.end()] taking a long time to end

I'm developing a workout app with a mirrored workout session. I'm having problems with sessions being out of sync. For example, when the workout is ended, it takes somewhere around a minute or two for it to actually fully end, so if during this time I start a new workout, then the sessions will be out of sync. I am using healthStore.recoverActiveWorkoutSession() to recover the workout session but it doesn't always work very well and in particular in the case when a workout has been manually ended (but ending hasn't completed) it enters an out of sync mode.

The reason why this case is happening is because I have an third party sensor connected to this mirrored workout session and if the sensor is out of range or turned off, I end the workout. However, if the person had accidentally gone out of range, they would reconnect to the app and restart the workout as soon as they realize and in that case, when the workout hasn't fully ended, it doesn't recover appropriately.

I have spent weeks trying to debug this with no luck so any advice will be appreciated.

Does the following sample code demonstrate the same issue?

If yes, I’d suggest that you file a feedback report with a sysdiagnose for the HealthKit team to investigate – If you do so, please share your report ID here and I'd make sure it is routed to the team.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Workout session [session.end()] taking a long time to end
 
 
Q