Detecting when Workout Session is being forcibly closed/ended

I noticied that my workout session is sometimes being killed by apple when the app is in the background and it seems that the func workoutSession(_ workoutSession: HKWorkoutSession, didChangeTo toState: HKWorkoutSessionState, from fromState: HKWorkoutSessionState, date: Date) { is only being called when the app comes back into the foreground.

I wonder if there is a way for us to get notified when the workout is about to die or has already been killed.

Thanks