Search
♻️

[iOS] App Life Cycle (iOS 12 and before)

부제
카테고리
iOS
세부 카테고리
LifeCycle
Combine 카테고리
최종편집일
2022/07/16 17:10
작성중
관련된 포스팅
생성 일시
2022/07/16 14:51
태그
iOS 12 이전까지의 앱의 생명주기 동작에 대해 알아보려고 합니다.

App life cycle

App state

앱의 상태에는 크게 5가지가 존재한다.
1.
Not Running: 실행되지 않거나  종료된 상태.
2.
InActive: 앱이 Foreground 상태로 돌아가지만, 이벤트는 받지 않는 상태, 앱의 상태 전환 과정에서 잠깐 머무는 단계
a.
앱 스위쳐 ( 아래에서 위로 스와이프 하는 순간 ) InActive 상태가 된다.
3.
Active: 일반적으로 앱이 돌아가는 상태 (이벤트를 받는 단계)
4.
Background: 앱이 Suspended(유예 상태) 상태로 진입하기 전 거치는 상태
a.
음악, 통화 앱 같은 경우는 background에 머무름
b.
보통 다른 앱들은 바로 Suspended 상태로 넘어감.
c.
background 로 들어가면 앱이 종료되었다고 봐야한다.
5.
Suspended: 앱이 Background 상태에 있지만, 아무 코드도 실행하지 않는 상태시스템이 임의로 Background 상태의 앱을 Suspended 상태로 만든다.(리소스 해제)
a.
일반적으로 Not Running 과 동일한 상태.
주요 작업은 Active 와 Background 상태에서 수행됨.

AppDelegate

위에서 보았던 상태들 간의 전환시 수행할 동작을 담는 파일이라고 생각하면 됩니다.
AppDelegate 객체는 UIResponderUIApplicationDelegate을 상속 및 참조하고 있습니다

UIResponder

앱에서 발생하는 이벤트들을 담고 있는 추상형 인터페이스 객체로 View와 사용자의 이벤트간의 연결을 관리하는 역할

UIApplicationDelegate

UIApplication 객체의 작업에 개발자가 접근할 수 있도록 하는 메소드들을 담고 있음.
UIApplicationDelegate 을 통해 앱의 상태 변환시 수행할 작업을 작성할 수 있음.
// AppDelegate.swift import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { return true } func applicationWillResignActive(_ application: UIApplication) { } func applicationDidEnterBackground(_ application: UIApplication) { //Tells the delegate that the app is now in the background. // } func applicationWillEnterForeground(_ application: UIApplication) { //Tells the delegate that the app is about to enter the foreground. } func applicationDidBecomeActive(_ application: UIApplication) { } func applicationWillTerminate(_ application: UIApplication) { }
Swift
복사