AppDelegateでアプリのフォアグランドやバックへの移動のコールバックを取得できます。
swiftuiなどのviewやViewController側でそのコールバックを取得するためには、NotificationCenterでオブザーバを設定しキャッチします。
didEnterBackgroundNotificationでバックへの移動のコールバックを取得できます
ここら辺の一覧はドキュメントを参考
https://developer.apple.com/documentation/uikit/uiapplication/1623071-didenterbackgroundnotification
その他のコールバックは「Responding to App Life-Cycle Events」を参照
NotificationCenter.default.addObserver(forName: UIApplication.didEnterBackgroundNotification, object: nil, queue: nil) { _ in
// do something
}