โ๏ธ ์๋ช ์ฃผ๊ธฐ (Life Cycle)
์๋ช ์ฃผ๊ธฐ๋, ์ฑ์ด ์ต์ด๋ก ์คํ๋๋ ์์ ๋ถํฐ ์ข ๋ฃ๋๋ ์์ ๊น์ง์ ์ํ๋ฅผ ์๋ฏธํ๋ค.
๊ทธ๋ ๋ค๋ฉด ์ด๋ฐ ์ฑ์ ์ํ๊ฐ ๋ฌด์์ธ๊ฐ ํ๋ฉด, "the current state of your app determines what it can and can’t do at any time." ์ฆ, ํ์ฌ ์์ ์์ ์ฑ์ด ๋ฌด์์ ํ ์ ์๋๋๋ฅผ ๊ฒฐ์ ์ง๋ ๊ฒ์ ๋ปํ๋ค.
์ฑ์ ๊ฐ๋ฐ ๋ฐ ์ฌ์ฉ์ ํ๋ค๋ณด๋ฉด ์ฌ์ฉ์ค์ธ ์ฑ์ ๋ฐฑ๊ทธ๋ผ์ด๋๋ก ์ ์ ๋ณด๋ผ ๋๋ ์๊ณ (์นดํก์ผ๋ก ๋ฐ์ ๊ณ์ข๋ฒํธ๋ฅผ ๋ณต์ฌํ๊ณ , ๊ทธ๋๋ก ์ํ์ฑ์ ์ผ์ ๋ถ์ฌ๋๋๋ค๊ฑฐ๋ ํ๋ ์ํฉ), ๋ฐฑ๊ทธ๋ผ์ด๋์ ๋ ์ฑ๋ก ํด๋น ์ฑ์ ๊ณ์ ์ฌ์ฉํ ๋๋ ์๊ณ (์ ํ๋ธ ๋ฎค์ง์ ์ฌ์ฉ์ค์ธ ์ฑ๋ก ๋ค๋ฅธ ์ฑ์ ๋ฉ์ธ์ผ๋ก ์ฌ์ฉํ๊ณ ์์ ์๋ ์๊ณ ), ํฌ๊ทธ๋ผ์ด๋ ์ํ๋ก ๊ทธ ์ฑ์ ์ด์ฉํ ๋๋ ์๋ค.
์ด๋ฐ ์ผ๋ จ์ ๊ณผ์ ๋ค์ ์ฑ์ ์๋ช ์ฃผ๊ธฐ๋ผ๊ณ ํํํ๊ธฐ๋ ํ๋ค.
โ๏ธ ์ฑ์ ์ํ
ํฌ๊ทธ๋ผ์ด๋/๋ฐฑ๊ทธ๋ผ์ด๋์์ ์ผ์ด๋๋ ์ฑ ์ํ๋ ํฌ๊ฒ 5๊ฐ์ง๊ฐ ์๋ค.
Not Running :
- ์ฑ์ด ์คํ๋์ง ์์๊ฑฐ๋, ์์คํ ์ ์ํด ์ข ๋ฃ๋์ด ๋์ด์ ๋์ํ์ง ์๋ ์ํ
application(_:willFinishLaunchingWithOptions)
//์ต์ด ์คํ๋ ๋ ํธ์ถ๋๋ ๋ฉ์๋
application(_:didFinishLaunchingWithOptions)
//ํ๋ฉด์ด ์ฌ์ฉ์์๊ฒ ๋ณด์ฌ์ง๊ธฐ ์ง์ ์ ํธ์ถ๋๋ ๋ฉ์๋.
//์ด๊ธฐํ ์ฝ๋ ์์ฑ
applicationWillTerminate(_:)
//์ฑ์ด ์ข
๋ฃ๋๊ธฐ ์ง์ ์ ํธ์ถ๋๋ ๋ฉ์๋.
Inactive (Foreground):
- ์ฑ์ด ์คํ ๋์ด foreground์ ์ง์ ํ์ผ๋ ์ด๋ฒคํธ๋ฅผ ๋ฐ๊ณ ์์ง ์์ ์ํ.
- ์ฑ ์คํ ์ค ๋ฏธ๋ฆฌ์๋ฆผ ๋ฑ ํ๋ฉด์ ๋ฎํ์ ์ฑ์ด ์ด๋ฒคํธ๋ ๋ฐ์ง ๋ชปํ๋ ์ํ.
- ์ฑ ์คํ ์ ํ์์ ์ผ๋ก ๊ฑฐ์น๊ฒ ๋๋ ์ ํ ๊ณผ์ .
Active (Foreground) :
- ์ฑ์ด foreground์์ ์คํ ์ค์ด๋ฉฐ ์ด๋ฒคํธ๋ฅผ ๋ฐ๊ณ ์๋ ์ํ.
Background :
- ๋ฐฑ๊ทธ๋ผ์ด๋ ์ํ์์ ๋ค๋ฅธ ์ฑ์ผ๋ก ์ ํ๋ ์ํ์ด๊ฑฐ๋ ์ฌ์ฉ์ค์ธ ์ฑ์ ๋๊ฐ์ ๋์ ์ํ.
- ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์์ ์ ์คํ (e.g. ์ ํ๋ธ ๋ฎค์ง ์คํํ ์ฑ๋ก ์ฌํ๋ฆฌ ์ฌ์ฉ์ด๋ ์นํฐ ์ฑ์ ์ฌ์ฉ)๋ฑ์ ๋ปํจ.
- ์ผ์ ์๊ฐ ์ฌ์ฉํ์ง ์์ผ๋ฉด suspended ์ํ๊ฐ ๋จ.
Suspended :
- ๋ฐฑ๊ทธ๋ผ์ด๋ ์ํ์์ ๊ทธ ์ด๋ ํ ์ด๋ฒคํธ๋ ๋ฐ์ํ์ง ์์ ์ํ.
- ๋ฉ๋ชจ๋ฆฌ์์ ์ฌ๋ผ๊ฐ ์์ผ๋, ์ด๋ฒคํธ๊ฐ ์๊ธฐ ๋๋ฌธ์ ์ค์ง์ ์ผ๋ก ์ฌ์ฉ ์ค์ธ ์ํ๊ฐ ์๋.
๐ ์ฐธ์กฐ
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
'๐ Dev > UIKit' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[UIKit] CustomView (0) | 2023.11.30 |
---|---|
[UIKit] Font ์ค์ ํ๊ธฐ (0) | 2023.11.02 |
[UIKit/Storyboard] ํค๋ณด๋ ๋ด๋ฆฌ๊ธฐ (0) | 2023.07.30 |
[UIKit/Storyboard] ํ ํ๋ก์ ํธ์์ ๋ค๋ฅธ ์คํ ๋ฆฌ๋ณด๋ ๋ณด๋ ๋ฒ (0) | 2023.07.30 |
[UIKit/Storyboard] ์์ธ๋ ํจ์ (@IBOutlet)๊ณผ ์ก์ ํจ์ (@IBAction) (0) | 2023.07.29 |