iOS - AppDelegate, SceneDelegate
AppDelegate.swift의 역할
1. AppDelegate클래스를 정의
AppDelegate.swift의 존재로 -> AppDelegate 클래스가 생성됨 -> 이 클래스의 인스턴스인 app delegate(우리 앱의 객체)
-> 앱의 상태에 따라 응답하는 콘텐츠가 그려지는 창(window)을 만듬
2. entry point와, 앱의 입력 이벤트를 전달하는 run loop를 생성
Apple이 기본적으로 제공하는 AppDelegate 메소드
func application(_: didFinishLaunchingWithOptions: ) -> Bool
: 이 메서드 안에서 application의 setup을 진행
func application(_: configurationForConnecting:options: ) -> UISceneConfiguration
: application이 새로운 scene/window를 제공하려고 할 때 불리는 메서드
func application(_: didDiscardSceneSessions: )
: 사용자가 scene을 버릴 때 불리는 메서드 (swipe로 multitasking windwo를 없앤다던지, 코드로서 없애는 경우 등등)
SceneDelegate
화면에 무엇(scene/window)을 보여줄지 관리하는 역할을 한다.
Apple이 기본적으로 제공하는 SceneDelegate 메소드
scene(_: willConnectTo: options: )
: UISceneSession lifecycle에서 제일 처음 불리는 메소드로 첫 content view, 새로운 UIWindow를 생성하고 window의 rootViewController를 설정한다. 과거에 disconnected 된 UI를 되돌릴 때도 쓰기도 한다.
sceneWillEnterForeground(_ :)
: scene이 foreground로 전환될 때 불리는 메소드 (background → foreground 가 되었을 때 or 처음 active 상태가 되었을 때)
sceneDidBecomeActive(_ :)
: scene이 setup 되고 화면에 보여지면서 준비가 완료되면 불리는 메소드 (active 상태)
sceneWillResignActive(_ :)
: active한 상태에서 inactive 상태로 전환될 때 불리는 메소드 (전화가 왔을 때)
sceneDidEnterBackground(_ :)
: scene이 foreground에서 background로 전환 될 때 불리는 메소드. 다음에 다시 foreground에 돌아 올 때 복원할 수 있도록 state 정보를 저장하거나, 데이터를 저장, 공유 자원 돌려주는 등의 일을 하도록 해야한다.
sceneDidDisconnect(_ :)
: scene이 background로 들어가서 disconnect(App 종료 X, session에서 끊어짐O) 될 때 시스템이 자원을 확보하기 위해 불리는 메소드. 생성이 쉬운 데이터들은 돌려주고(필요 없는 자원은 돌려주고), 사용자의 input과 같이 재생성이 어려운 데이터는 갖고 있게끔 하는 작업을 해야한다.
[참고 : https://www.sueaty.com/134]