[SWIFT] Get the event that the iOS application moves to the back on the View side

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

Get the event that the iOS application moves to the back on the View side
[Swift UI] How to get the startup status of the application [iOS]
Address to the problem that the video is paused during background transition while playing video on iOS14
[IOS] How to get the table name from AWS DynamoDB
Apache Geode-Easy way to execute logic on the server side
How to disable Set-Cookie from API on the front side
[Docker] How to back up and restore the DB data of Rails application on docker-compose [MySQL]
How to make an application with ruby on rails (assuming that the environment has been built)
How to display 0 on the left side of the standard input value