Swift

UIKit: AppDelegate, UIApplicationDelegate

songmoro 2023. 9. 12. 01:39
728x90

iOS 13 이후 앱의 생명 주기

 

iOS 12 이전 앱의 생명 주기

 

 


Unattached

앱이 시작되지 않았거나, 실행되었지만 시스템에 의해 종료된 상태

목적: 데이터 구조 초기화, 실행에 필요한 리소스 확인, 메인 스레드에서 오래 걸리는 작업 수행

Foreground Inactive

앱이 전면에서 실행 중이지만, 아무런 이벤트를 받지 않고 있는 상태

목적: 앱 데이터 모델 갱신(디스크 또는 네트워크를 통해 데이터 로드), 사용자 인터페이스의 초기 작업

Foreground active

앱이 전면에서 실행 중이며, 이벤트를 받고 있는 상태

Background

앱이 백그라운드에 있지만 여전히 코드가 실행되고 있는 상태

대부분의 앱은 Suspended 상태로 전환되는 도중 일시적으로 이 상태에 진입하며 파일 다운로드 및 업로드, 연산 처리 등 여분의 시간이 더 필요한 앱일 경우 특정 시간 동안 Background 상태로 남아 있습니다.

목적: Background로 전환 시 사용자의 데이터를 저장하고 주요 작업을 일시 중지하거나, 메모리를 확보하고 앱이 보유하고 있는 공유 리소스를 확보하기 위해

Suspended

앱이 메모리에 유지되지만 실행되는 코드가 없는 상태

목적: 메모리가 부족한 상황이 되면 시스템은 전면에 있는 앱의 여유 메모리 공간 확보를 위해 Suspended 상태의 앱을 정리


UIApplicationDelegate

func application(UIApplication, willFinishLaunchingWithOptions: [UIApplication.LaunchOptionsKey : Any]?) -> Bool
// 앱이 구동되어 필요한 초기 실행 과정이 완료되기 직전에 호출

func application(UIApplication, didFinishLaunchingWithOptions: [UIApplication.LaunchOptionsKey : Any]?) -> B
// 앱이 사용자에게 표시되기 직전에 호출

func application(UIApplication, configurationForConnecting: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration
// 앱이 새로운 scene 또는 window를 제공하려고 할 때 호출

func application(UIApplication, didDiscardSceneSessions: Set<UISceneSession>)
// 유저가 App switcher를 통해 하나 이상의 scene을 닫았을 때 호출

func applicationWillEnterForeground(UIApplication)
// 앱이 Foreground로 진입할 때 호출

func applicationDidBecomeActive(UIApplication)
// 앱이 Active 상태가 되어 실행 중일 때 호출

func applicationWillResignActive(UIApplication)
// 앱이 Background 상태로 진입할 때 호출

func applicationDidEnterBackground(UIApplication)
// 앱이 Background 상태가 되었을 때 호출

func applicationWillTerminate(UIApplication)
// 앱이 종료되었을 때

UISceneDelegate

func scene(UIScene, willConnectTo: UISceneSession, options: UIScene.ConnectionOptions)
// scene이 추가 되었을 때 호출

func sceneDidDisconnect(UIScene)
// scene이 제거 되었을 때 호출

func sceneWillEnterForeground(UIScene)
// scene이 Foreground로 진입할 때 호출

func sceneDidBecomeActive(UIScene)
// scene이 Active 상태가 되어 실행 중일 때 호출

func sceneWillResignActive(UIScene)
// scene이 Background 상태로 진입할 때 호출

func sceneDidEnterBackground(UIScene)
// scene이 Background 상태가 되었을 때 호출

 


참고

Managing your app’s life cycle

Responding to the launch of your app

Preparing your UI to run in the foreground

Preparing your UI to run in the background

[iOS] LifeCycle(생명주기)

[iOS] 앱의 상태 변화에 따른 AppDelegate

 

728x90
댓글수0