iOS 13부터 도입된 SceneDelegate는 멀티 윈도우 환경을 지원하기 위해 등장한 구조입니다.
기존의 AppDelegate가 처리하던 일부 역할을 분리하여, 각 씬(창)에 대한 생명 주기를 별도로 관리할 수 있도록 합니다.
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)
func sceneDidBecomeActive(_ scene: UIScene)
func sceneWillResignActive(_ scene: UIScene)
func sceneWillEnterForeground(_ scene: UIScene)
func sceneDidEnterBackground(_ scene: UIScene)
func sceneDidDisconnect(_ scene: UIScene)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
let window = UIWindow(windowScene: windowScene)
window.rootViewController = YourInitialViewController()
self.window = window
window.makeKeyAndVisible()
}
}
| 항목 | AppDelegate | SceneDelegate |
|---|---|---|
| iOS 버전 | 모든 버전 (iOS 13 이상에서는 제한됨) | iOS 13 이상 |
| 역할 | 앱 전체의 라이프사이클 관리 | 각 윈도우(씬)의 라이프사이클 관리 |
| 예시 | 앱 실행, 푸시 알림 등록 등 | 창 전환, 멀티 윈도우 등 |
SceneDelegate는 각 씬 단위로 상태를 관리할 수 있게 만들어, 복잡한 앱 환경(특히 멀티 윈도우)을 더 잘 지원할 수 있도록 설계된 구조입니다. iOS 13 이상을 타겟으로 하는 앱에서는 반드시 구조를 이해하고 활용해야 안정적인 앱 상태 관리를 할 수 있습니다.