๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
iOS ๐ŸŽ/iOS

Managing iOS App's Life Cycle

by yongmin.Lee 2021. 2. 24.

1. Overview

Respond to system notifications when your app is in the foreground or background, and handle other significant system-related events. The current state of your app determines what it can and cannot do at any time. For example, a foreground app has the user’s attention, so it has priority over system resources, including the CPU. By contrast, a background app must do as little work as possible, and preferably nothing, because it is offscreen. As your app changes from state to state, you must adjust its behavior accordingly.

2. Respond to life-cycle events. (in iOS 12 and earlier)

2-1. App States

  • Not Running: ์•„๋ฌด๊ฒƒ๋„ ์‹คํ–‰ํ•˜์ง€ ์•Š์€ ์ƒํƒœ
  • InActive: ์•ฑ์ด Foreground ์ƒํƒœ๋กœ ๋Œ์•„๊ฐ€์ง€๋งŒ, ์ด๋ฒคํŠธ๋Š” ๋ฐ›์ง€ ์•Š๋Š” ์ƒํƒœ, ์•ฑ์˜ ์ƒํƒœ ์ „ํ™˜ ๊ณผ์ •์—์„œ ์ž ๊น ๋จธ๋ฌด๋Š” ๋‹จ๊ณ„.
  • Active: ์ผ๋ฐ˜์ ์œผ๋กœ ์•ฑ์ด ๋Œ์•„๊ฐ€๋Š” ์ƒํƒœ
  • Background: ์•ฑ์ด Suspended(์œ ์˜ˆ ์ƒํƒœ) ์ƒํƒœ๋กœ ์ง„์ž…ํ•˜๊ธฐ ์ „ ๊ฑฐ์น˜๋Š” ์ƒํƒœ, ์‹คํ–‰๋˜๋Š” ์ฝ”๋“œ๋Š” ์žˆ๋Š” ์ƒํƒœ
  • Suspended: ์•ฑ์ด Background ์ƒํƒœ์— ์žˆ์ง€๋งŒ, ์•„๋ฌด ์ฝ”๋“œ๋„ ์‹คํ–‰ํ•˜์ง€ ์•Š๋Š” ์ƒํƒœ, ์‹œ์Šคํ…œ์ด ์ž„์˜๋กœ Background ์ƒํƒœ์˜ ์•ฑ์„ Suspended ์ƒํƒœ๋กœ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

2-2. App transitions to perform the following task

At launch, initialize your app’s data structures and UI. 

- At activation, finish configuring your UI and prepare to interact with the user. 

- Upon deactivation, save data and quiet your app’s behavior. 

- Upon entering the background state, finish crucial tasks, free up as much memory as possible, and prepare for your app snapshot.

- At termination, stop all work immediately and release any shared resources. 

3. Respond to life-cycle events in a scene-based app. (in iOS 13 and later)

 the state transitions for scenes. 

- When UIKit connects a scene to your app, configure your scene’s initial UI and load the data your scene needs.

- When transitioning to the foreground-active state, configure your UI and prepare to interact with the user. 

- Upon leaving the foreground-active state, save data and quiet your app’s behavior. 

- Upon entering the background state, finish crucial tasks, free up as much memory as possible, and prepare for your app snapshot.

- At scene disconnection, clean up any shared resources associated with the scene.

- In addition to scene-related events, you must also respond to the launch of your app using your UIApplicationDelegate object. For information about what to do at app launch