SceneDelegate와 AppDelegate 구조 차이

개요

iOS 13의 등장과 함께 멀티 윈도우 기능이 도입되면서 iOS 앱의 생명주기 관리 구조가 크게 변화했습니다. 기존에 AppDelegate 하나가 담당했던 모든 생명주기 관리가 AppDelegate와 SceneDelegate로 역할이 분담되면서 더욱 세분화된 관리가 가능해졌습니다[1][2].

iOS 13 이전의 AppDelegate 구조

단일 책임 구조

iOS 13 이전에는 AppDelegate가 앱의 모든 생명주기를 관리했습니다[3][4]. 하나의 앱에는 단 하나의 윈도우만 존재했으며, AppDelegate가 다음과 같은 역할을 모두 담당했습니다:

  • Process Lifecycle: 앱의 시작과 종료
  • UI Lifecycle: Foreground/Background 상태 전환
  • Window 관리: 단일 윈도우의 상태 관리

주요 메서드

// 앱 시작
func application(_:didFinishLaunchingWithOptions:)

// 앱 상태 전환
func applicationDidBecomeActive(_:)
func applicationWillResignActive(_:)
func applicationDidEnterBackground(_:)
func applicationWillEnterForeground(_:)

// 앱 종료
func applicationWillTerminate(_:)

iOS 13 이후의 분리된 구조

역할 분담

iOS 13부터는 멀티 윈도우 지원을 위해 책임이 명확히 분리되었습니다[1][2][3]:

AppDelegate

  • Process Lifecycle 관리
  • Session Lifecycle 관리
  • 앱 전체의 초기화 및 설정
  • 외부 알림 처리 (배터리 부족, 다운로드 완료 등)
  • Push Notification 등 서비스 등록

SceneDelegate

  • UI Lifecycle 관리
  • 각 Scene의 상태 전환 처리
  • 멀티 윈도우 환경에서 개별 Scene 관리

Scene 개념의 도입

Scene은 앱 UI의 하나의 인스턴스를 나타내며, 다음과 같은 특징을 가집니다[5][6][7]:

  • 하나의 앱이 여러 Scene을 동시에 가질 수 있음
  • 각 Scene은 독립적인 생명주기를 가짐
  • Scene들은 같은 메모리와 프로세스 공간을 공유하면서 동시에 실행
  • 하나의 뷰 계층구조(View Hierarchy)를 포함

AppDelegate의 변화된 역할

Session Lifecycle 관리

iOS 13 이후 AppDelegate에는 Session Lifecycle 관리 메서드가 추가되었습니다[5][6]:

// Scene Session 생성
func application(_:configurationForConnecting:options:) -> UISceneConfiguration

// Scene Session 삭제
func application(_:didDiscardSceneSessions:)

핵심 책임

현재 AppDelegate는 다음과 같은 역할을 담당합니다[1][5]:

  1. 앱의 중요한 데이터 구조 초기화
  2. 앱의 Scene 환경설정
  3. 앱 외부 알림에 대한 응답
  4. 앱 자체를 대상으로 하는 이벤트 처리
  5. 필요한 서비스 등록 (Push Notification 등)

SceneDelegate의 역할과 메서드

UI 상태 관리

SceneDelegate는 각 Scene의 UI 생명주기를 독립적으로 관리합니다[1][8]:

// Scene 연결 및 초기화
func scene(_:willConnectTo:options:)

// Scene 상태 전환
func sceneDidBecomeActive(_:)
func sceneWillResignActive(_:)
func sceneWillEnterForeground(_:)
func sceneDidEnterBackground(_:)

// Scene 연결 해제
func sceneDidDisconnect(_:)

각 메서드의 역할

  • scene(_:willConnectTo:options:): Scene이 앱에 추가될 때 호출[8]
  • sceneDidBecomeActive(_:): Scene이 비활성에서 활성 상태로 전환[3]
  • sceneWillResignActive(_:): Scene이 활성에서 비활성 상태로 전환[3]
  • sceneWillEnterForeground(_:): Scene이 백그라운드에서 포그라운드로 전환[3]
  • sceneDidEnterBackground(_:): Scene이 포그라운드에서 백그라운드로 전환[3]
  • sceneDidDisconnect(_:): Scene 연결이 해제될 때 호출[8]

Scene Session의 역할

Scene Session은 Scene의 고유한 런타임 인스턴스를 관리합니다[5][6][7]:

  • Scene의 고유 식별자와 구성 정보 보관
  • Scene의 생명주기 동안 정보 유지
  • 사용자가 Scene을 종료할 때 Session 파괴
  • UIKit이 자동으로 생성하고 관리

멀티 윈도우 지원의 핵심

이러한 구조 변화의 주요 목적은 멀티 윈도우 환경 지원입니다[2][4]:

  • iPad의 Split View: 한 화면에 여러 앱 동시 실행
  • Multiple Scene: 같은 앱의 여러 인스턴스 동시 실행
  • 독립적 상태 관리: 각 Scene이 서로 다른 상태를 가질 수 있음

호환성 고려사항

iOS 12 이하 버전 지원이 필요한 경우에는 SceneDelegate를 사용하지 않도록 설정할 수 있으며, 이 경우 AppDelegate가 모든 생명주기를 관리하게 됩니다[5][4].

이러한 구조적 변화를 통해 iOS 앱은 더욱 유연하고 강력한 멀티 윈도우 환경을 지원할 수 있게 되었으며, 개발자는 각 Scene의 상태를 독립적으로 관리하여 더 나은 사용자 경험을 제공할 수 있습니다[1].

출처
[1] [iOS 앱 개발의 핵심 이해] SceneDelegate와 AppDelegate의 차이점 https://neep305.tistory.com/87
[2] [iOS] AppDelegate vs SceneDelegate 차이 – velog https://velog.io/@maddie/iOS-AppDelegate-vs-SceneDelegate-%EC%B0%A8%EC%9D%B4
[3] [iOS] Scene Delegate vs App Delegate – velog https://velog.io/@lhj26/iOS-Scene-Delegate-vs-App-Delegate
[4] [iOS] 생애주기 및 AppDelegate, SceneDelegate의 역할 – 개발 노트 https://taehun0933.tistory.com/32
[5] iOS) AppDelegate, SceneDelegate – Deving – 티스토리 https://snowee.tistory.com/40
[6] AppDelegate & SceneDelegate – My selfish tech blog – 티스토리 https://yellowc-137.tistory.com/34
[7] [iOS] iOS13이후의 AppDelegate와 SceneDelegate – 다 한때 – 티스토리 https://jouureee.tistory.com/65
[8] [iOS] SceneDelegate는 무엇일까? – PurpleLog – 티스토리 https://purple-log.tistory.com/28
[9] 1. iOS 앱의 상태 변화에 따라 호출되는 메서드 종류에 대해 설명 … https://hackmd.io/@leonFather/ByhTzKEw2
[10] [iOS] 생명주기 + AppDelegate & SceneDelegate – josee2 Devlog https://josee2.tistory.com/40
[11] 멀티 윈도우는 어떻게 사용하나요? | 고객지원 – LG전자 https://www.lge.co.kr/support/solutions-20151916636905
[12] 멀티윈도우 분할 화면을 사용해 보세요. – 삼성전자서비스 https://www.samsungsvc.co.kr/solution/42391
[13] [iOS] SceneDelegate & AppDelegate의 역할 – SUEATY 발은 개발 https://sueaty.tistory.com/134
[14] [iOS] AppDelegate와 SceneDelegate – velog https://velog.io/@dev-lena/iOS-AppDelegate%EC%99%80-SceneDelegate
[15] [iOS][swiftUI] iOS13에서 분할된 AppDelegate와 추가된 … https://huniroom.tistory.com/entry/iOSswiftUI-iOS13%EC%97%90%EC%84%9C-%EB%B6%84%ED%95%A0%EB%90%9C-AppDelegate%EC%99%80-%EC%B6%94%EA%B0%80%EB%90%9CSceneDelegate%EC%9D%B4%ED%95%B4%ED%95%98%EA%B8%B0
[16] [iOS] AppDelegate, SceneDelegate (iOS 13 이전 이후) – velog https://velog.io/@nnnyeong/iOS-AppDelegate-SceneDelegate
[17] Scene 기반 App LifeCycle (after iOS 13) – 공태현 https://luke-kong.oopy.io/ios/scene-life-cycle

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다