-
(iOS) Life Cycle (AppDelegate / SceneDelegate)iOS💖 2024. 9. 6. 17:49
- iOS 시스템은, 현재 집중되고 있는(= 현재 실행중인) 앱에 리소스를 몰아준다.
- 앱의 상태 변경(foreground / background) 에 따라 대응할 수 있는 앱을 만들어야함
- 앱의 Life cycle의 이해가 중요한 이유!
- background app은 가능하면 반드시 리소스를 적게 차지해야한다.
- 앱의 상태가 변경되면, UIKit은 적절함 delegate object의 메소드를 호출하여 알려준다.
- 앱의 Life cycle의 이해가 중요한 이유!
- UIApplicationDelegate (App Delegate)
- iOS 12 or 그 이전
- 하나의 앱에서 하나의 life-cycle 이벤트 실행

App Delegate - UISceneDelegate (Scene Delegate)
- iOS 13 or 그 이후
- scene-based app (multi-window) 에서의 life-cycle 이벤트 실행
- App Delegate과 거의 비슷함
- iOS 13 이전에는 하나의 앱이 하나의 scene 에 적용 됐다면,
13이후에서는 multi-window가 되다보니, 앱별로 여러개의 Scene Delegate이 관리될 수 있다.

Scene Delgate
- Scene?
- scenes은 여러개의 UI (= multi-window)들의 인스턴스를 관리한다.
- UIKit은 UIWindowScene 객체를 사용하여 각각의 앱의 UI를 관리한다.
- 하나의 scene은 하나의 UI의 인스턴스를 표현하기 위해, windows, view controllers,
UIKit과 앱과의 상호작용 조정을 위한 UIWindowSceneDelegate 객체를 포함한다. - scenes은 서로 동시에 실행되어 동일한 메모리와 앱 프로레스 공간을 공유한다.
- scenes은 리소스들을 적절한 UI 인스턴스로 보낸다.
- 결과적으로, 단일 앱에는 동시에 여러 scenes을 가질 수 있고,
scenes delegate 객체들이 동시에 활성화 될 수 있다. (아래의 사진)
- scenes은 여러개의 UI (= multi-window)들의 인스턴스를 관리한다.

한 앱 (Memo App)에서 여러개의 scenes 와 scene delegate 객체들이 동시에 활성화되는 얘시 참고자료)
https://developer.apple.com/documentation/uikit/app_and_environment/managing_your_app_s_life_cycle
Managing your app’s life cycle | Apple Developer Documentation
Respond to system notifications when your app is in the foreground or background, and handle other significant system-related events.
developer.apple.com
https://developer.apple.com/documentation/uikit/app_and_environment/scenes
Scenes | Apple Developer Documentation
Manage multiple instances of your app’s UI simultaneously, and direct resources to the appropriate instance of your UI.
developer.apple.com
https://developer.apple.com/videos/play/wwdc2019/258/
Architecting Your App for Multiple Windows - WWDC19 - Videos - Apple Developer
Dive into the details about what it means to support multitasking in iOS 13. Understand how previous best practices fit together with new...
developer.apple.com
'iOS💖' 카테고리의 다른 글
(Swift) CollectionView Estimate Size 코드 설정 (0) 2024.09.10 (Swift) CollectionView contentInset (padding 주는 방법) (4) 2024.09.10 (Swift) POP (Protocol Oriented Programming) (0) 2024.09.04 (Swift) Structures VS. Classes (0) 2024.09.03 (Swift) deinitializer (3) 2024.09.03