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

[iOS ๋ฉด์ ‘์งˆ๋ฌธ]์•ฑ ์ƒ๋ช…์ฃผ๊ธฐ(App LifeCycle) (1) - ๊ฐœ๋…(์•ฑ์ด In-Active ์ƒํƒœ๊ฐ€ ๋˜๋Š” ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ ์„ค๋ช…ํ•˜์‹œ์˜ค.)

by Fomagran ๐Ÿ’ป 2020. 10. 20.
728x90
๋ฐ˜์‘ํ˜•

์•ˆ๋…•ํ•˜์„ธ์š” Foma ์ž…๋‹ˆ๋‹ค!

 

์˜ค๋Š˜ ์•Œ์•„๋ณผ ๋ณผ ๊ฑด ๋ฐ”๋กœ ์•ฑ ์ƒ๋ช…์ฃผ๊ธฐ์ž…๋‹ˆ๋‹ค.

 

๋ชจ๋“  iOS ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ 5๊ฐ€์ง€ ์ƒํƒœ์— ์žˆ์Šต๋‹ˆ๋‹ค.

States


1. Not running

์•ฑ์ด ์‹คํ–‰๋˜์ง€ ์•Š์•˜๊ฑฐ๋‚˜ ์™„์ „ํžˆ ์ข…๋ฃŒ๋˜์—ˆ์„ ๋•Œ ์ƒํƒœ์ž…๋‹ˆ๋‹ค.

 

2.In-active(๋น„ํ™œ์„ฑํ™”)

์•ฑ์ด ์‹คํ–‰๋˜๋ฉด์„œ ํฌ์–ด๊ทธ๋ผ์šด๋“œ์— ์ง„์ž…ํ•˜์ง€๋งŒ ์–ด๋– ํ•œ ์ด๋ฒคํŠธ๋„ ๋ฐ›์ง€ ์•Š๋Š” ์ƒํƒœ์ž…๋‹ˆ๋‹ค.

 

3.Active(ํ™œ์„ฑํ™”)

์•ฑ์ด ์‹คํ–‰ ์ค‘์ด๋ฉฐ ํฌ์–ด๊ทธ๋ผ์šด๋“œ์— ์žˆ๊ณ  ์ด๋ฒคํŠธ๋ฅผ ๋ฐ›๊ณ  ์žˆ๋Š” ์ƒํƒœ์ž…๋‹ˆ๋‹ค.

 

4.Background

์•ฑ์ด ๋ฐฑ๊ทธ๋ผ์šด๋“œ์— ์žˆ์œผ๋ฉฐ ๋‹ค๋ฅธ ์•ฑ์œผ๋กœ ์ „ํ™˜๋˜์—ˆ๊ฑฐ๋‚˜ ํ™ˆ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ๋ฐ–์œผ๋กœ ๋‚˜๊ฐ”์„ ๋•Œ์˜ ์ƒํƒœ์ž…๋‹ˆ๋‹ค.

 

5.Suspended

๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ํŠน๋ณ„ํ•œ ์ž‘์—…์ด ์—†์„ ๊ฒฝ์šฐ ์ „ํ™˜๋˜๋Š” ์ƒํƒœ์ž…๋‹ˆ๋‹ค.

 

 

์•ฑ์˜ ์ƒ๋ช…์ฃผ๊ธฐ ์ƒํƒœ์— ๋”ฐ๋ผ์„œ AppDelegate์™€ SceneDelegate์—์„œ ํŠน์ • ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๊ฒŒ ๋˜๋Š”๋ฐ์š”.

Method


Not Running

application(_:willFinishLaunchingWithOptions:)

 

์•ฑ ์‹คํ–‰์„ ์ค€๋น„ํ•˜๋Š” ๋ฉ”์†Œ๋“œ์ž…๋‹ˆ๋‹ค.

 

ํ•„์š”ํ•œ ์ฃผ์š” ๊ฐ์ฒด๋“ค์„ ์ƒ์„ฑํ•˜๊ณ  ์•ฑ ์‹คํ–‰ ์ค€๋น„๊ฐ€ ๋๋‚˜๊ธฐ ์ง์ „์— ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค.

 

applicationDidFinishLaunching(_:)

 

์•ฑ ์‹คํ–‰์„ ์œ„ํ•œ ๋ชจ๋“  ์ค€๋น„๊ฐ€ ๋๋‚œ ํ›„ ํ™”๋ฉด์ด ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ง€๊ธฐ ์ง์ „์— ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค.

 

์ฃผ๋กœ ์ดˆ๊ธฐํ™” ์ฝ”๋“œ๋ฅผ ์ด๊ณณ์—๋‹ค ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

applicationWillTerminate(_:)

 

์•ฑ์ด ์ข…๋ฃŒ๋˜๊ธฐ ์ง์ „์— ํ˜ธ์ถœ๋œ๋‹ค.

 

(ํ•˜์ง€๋งŒ ๋ฉ”๋ชจ๋ฆฌ ํ™•๋ณด๋ฅผ ์œ„ํ•ด suspended ์ƒํƒœ์— ์žˆ๋Š” ์•ฑ์ด ์ข…๋ฃŒ๋  ๋•Œ๋‚˜ background ์ƒํƒœ์—์„œ ์‚ฌ์šฉ์ž์— ์˜ํ•ด ์ข…๋ฃŒ๋  ๋•Œ๋‚˜

์˜ค๋ฅ˜๋กœ ์ธํ•ด ์•ฑ์ด ์ข…๋ฃŒ๋  ๋•Œ๋Š” ํ˜ธ์ถœ๋˜์ง€ ์•Š๋Š”๋‹ค.)

 

In-Active

 

sceneWillEnterForeground(_:).

 

์•ฑ์ด ๋ฐฑ๊ทธ๋ผ์šด๋“œ๋‚˜ ๋‚ซ๋Ÿฌ๋‹์—์„œ ํฌ์–ด๊ทธ๋ผ์šด๋“œ๋กœ ๋“ค์–ด๊ฐ€๊ธฐ ์ง์ „์— ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค.

 

๋น„ํ™œ์„ฑํ™” ์ƒํƒœ๋ฅผ ๊ฑฐ์ณ ํ™œ์„ฑํ™” ์ƒํƒœ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

 

sceneWillResignActive(_:)

 

 

Active

 

sceneDidBecomeActive(_:)

 

์•ฑ์ด ๋น„ํ™œ์„ฑ์ƒํƒœ์—์„œ ํ™œ์„ฑ์ƒํƒœ๋กœ ์ง„์ž…ํ•˜๊ณ  ๋‚œ ์งํ›„ ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค.

 

์•ฑ์ด ์‹ค์ œ๋กœ ์‚ฌ์šฉ๋˜๊ธฐ ์ „์— ๋งˆ์ง€๋ง‰์œผ๋กœ ์ค€๋น„ํ•  ์ˆ˜ ์žˆ๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

Background

 

sceneDidEnterBackground(_:)

 

์•ฑ์ด ๋ฐฑ๊ทธ๋ผ์šด๋“œ ์ƒํƒœ๋กœ ๋“ค์–ด๊ฐ”์„ ๋•Œ ํ˜ธ์ถœ๋œ๋‹ค.

 

suspended ์ƒํƒœ๊ฐ€ ๋˜๊ธฐ ์ „ ์ค‘์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š” ๋“ฑ ์ข…๋ฃŒํ•˜๊ธฐ ์ „์— ํ•„์š”ํ•œ ์ž‘์—…์„ ํ•œ๋‹ค.

 

Suspended

 

๋”ฐ๋กœ ํ˜ธ์ถœ๋˜๋Š” ๋ฉ”์†Œ๋“œ๋Š” ์—†์œผ๋ฉฐ background์ƒํƒœ์—์„œ ํŠน๋ณ„ํ•œ ์ž‘์—…์ด ์—†์„ ๋•Œ ์ด ์ƒํƒœ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

 

๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ฉ”์†Œ๋“œ๋งˆ๋‹ค ํ˜ธ์ถœ๋˜๋Š” ๋ฉ”์„ธ์ง€๋ฅผ ์ถœ๋ ฅํ•ด๋ณด๋ฉด

Example Image & Video


 

 

Interview Question


Q. ์•ฑ์ด In-Active ์ƒํƒœ๊ฐ€ ๋˜๋Š” ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ ์„ค๋ช…ํ•˜์‹œ์˜ค.

 

์•ฑ์ด ๋ฐฑ๊ทธ๋ผ์šด๋“œ ์ƒํƒœ์—์„œ ๋‹ค์‹œ ํฌ์–ด๊ทธ๋ผ์šด๋“œ๋กœ ์ง„์ž…ํ•  ๋•Œ ์ธ์•กํ‹ฐ๋ธŒ์ƒํƒœ๋ฅผ ๊ฑฐ์ณ ์•กํ‹ฐ๋ธŒ ์ƒํƒœ๊ฐ€ ๋˜๊ณ 

๋˜ํ•œ ์•ฑ์ด ์‹คํ–‰๋  ๋•Œ ํฌ์–ด๊ทธ๋ผ์šด๋“œ์— ์ง„์ž…ํ•˜๋ฉด์„œ ๋‚ซ๋Ÿฌ๋‹์ƒํƒœ์—์„œ ์ธ์•ก์ดํŠธ์ƒํƒœ๋ฅผ ๊ฑฐ์ณ ์•กํ‹ฐ๋ธŒ ์ƒํƒœ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

 

๋ฉ”์†Œ๋“œ ์ˆœ์„œ๋กœ ๋ง์”€๋“œ๋ฆฌ๋ฉด  not running ์ƒํƒœ์—์„œ ์•ฑ ์‹คํ–‰ํ•˜๊ณ  ํฌ์–ด๊ทธ๋ผ์šด๋“œ ์ง์ „์— applicationDidFinishLaunching(_:) ์ด ํ˜ธ์ถœ๋˜๊ณ 

์ด์ œ ํฌ์–ด๊ทธ๋ผ์šด๋“œ์— ์ง„์ž…ํ•  ๋•Œ sceneWillEnterForeground(_:) ๊ฐ€ ํ˜ธ์ถœ๋˜๋ฉด์„œ ์ธ์•กํ‹ฐ๋ธŒ ์ƒํƒœ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

 

๋˜ํ•œ ์œ ์ €๊ฐ€ ๋ฐฑ๊ทธ๋ผ์šด๋“œ์— ์ง„์ž…ํ–ˆ์„๋•Œ sceneDidEnterBackground(_:)  ๊ฐ€ ํ˜ธ์ถœ๋˜๊ณ  

๋‹ค์‹œ ํฌ์–ด๊ทธ๋ผ์šด๋“œ์— ๋“ค์–ด๊ฐ€๊ฒŒ ๋  ๋•Œ sceneDidBecomeActive(_:) ์ด ํ˜ธ์ถœ๋˜๋Š”๋ฐ ์—ฌ๊ธฐ์„œ ์ธ์•กํ‹ฐ๋ธŒ ์ƒํƒœ๋ฅผ ๊ฑฐ์ณ๊ฐ€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

Github


์ „์ฒด์†Œ์Šค์ฝ”๋“œ

 

fomagran/AppLifeCyle

Contribute to fomagran/AppLifeCyle development by creating an account on GitHub.

github.com

 

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€