2
3

More than 3 years have passed since last update.

iOS アプリがバックに移行するイベントをView側で取得

Posted at

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
        }
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3