When a workout session is being recovered, if it is paused, the elapsed time will be incorrect. It will seem like that workout never was paused.
The recovery works fine if the workout was never paused.
Steps to reproduce:
- Implement recoverActiveWorkoutSession
- Start workout
- Pause session and print the elapsed time
- Stop simulator / cause crash
- When recoverActiveWorkoutSession is called the elapsed time will not equal the elapsed time when the session was paused.
Here is my implementation. I haven't seen any examples online.
guard let recovered = try? await healthStore.recoverActiveWorkoutSession() else {return}
self.session = recovered
self.builder = recovered.associatedWorkoutBuilder()
self.session?.delegate = self
self.builder?.delegate = self
self.builder?.dataSource = HKLiveWorkoutDataSource(healthStore: healthStore, workoutConfiguration: recovered.workoutConfiguration)
self.sessionState = recovered.state