You can get callbacks for moving your app to the foreground or back with AppDelegate. In order to get the callback on the view or view controller side such as swiftui, set the observer in NotificationCenter and catch it.
You can get the callback of the move to the back with didEnterBackgroundNotification Refer to the document for a list around here https://developer.apple.com/documentation/uikit/uiapplication/1623071-didenterbackgroundnotification See Responding to App Life-Cycle Events for other callbacks
NotificationCenter.default.addObserver(forName: UIApplication.didEnterBackgroundNotification, object: nil, queue: nil) { _ in
// do something
}
Recommended Posts