There isn't a guarantee and you likely get very little time.
It might be better to leave the recording in a reasonable state.
This might help...
https://stackoverflow.com/questions/68911874/how-to-detect-when-a-user-terminates-an-app-swift
Topic:
Media Technologies
SubTopic:
Audio
Tags: