์ƒˆ์†Œ์‹

๐Ÿ“ฑ iOS/-- UIKit

(iOS) - App Life Cycle, App Delegate, Scene Delegate

  • -

 

#iOS์•ฑ์˜ ์ƒํƒœ

 

 

#Not Running

์•„๋ฌด๊ฒƒ๋„ ์‹คํ–‰ํ•˜์ง€ ์•Š์€ ์ƒํƒœ, ํ˜น์€ ์‹คํ–‰์ค‘์ด์ง€๋งŒ ์‹œ์Šคํ…œ์— ์˜ํ•ด ์ข…๋ฃŒ๋œ ์ƒํƒœ๋ฅผ ๋งํ•จ

#Foreground - InActive

  • Forground์—์„œ ์•ฑ์ด ๋Œ์•„๊ฐ€๊ธด ํ•˜์ง€๋งŒ ์ด๋ฒคํŠธ๋ฅผ ๋ฐ›์ง€ ์•Š๋Š” ์ƒํƒœ.
  • ์•ฑ ์‹คํ–‰์ค‘์— ์ „ํ™”๊ฐ€ ์˜ค๊ฑฐ๋‚˜, ๋‹ค๋ฅธ ์•ฑ์œผ๋กœ ์ „ํ™˜ํ•˜๋ ค๊ณ  ํ•˜๊ฑฐ๋‚˜, ๋“ฑ๋“ฑ ์‚ฌ์šฉ์ž๊ฐ€ ์˜จ์ „ํžˆ full control์ด ๋ถˆ๊ฐ€ํ•œ ์ƒํƒœ๋ฅผ InActive์ƒํƒœ๋ผ๊ณ  ๋งํ•œ๋‹ค. (๊ฑฐ์˜ ๋ชจ๋“  ๊ฒฝ์šฐ์— ์ผ์‹œ์ ์ด๋‹ค)
  • Not Running ์ƒํƒœ์—์„œ ์•ฑ์„ ์‹คํ–‰์‹œ์ผœ Active๋กœ ๋ฐ”๊พธ๋ ค๋ฉด, InActive๋ฅผ ๊ฑฐ์ณ์•ผํ•œ๋‹ค. ๋ฐ˜๋Œ€์˜ ๊ฒฝ์šฐ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ InActive๋ฅผ ๊ฑฐ์ณ์•ผํ•œ๋‹ค.

#Foreground

  • ๋ฉ”๋ชจ๋ฆฌ์— ์•ฑ์ด ์ ์žฌ๋˜์–ด์žˆ์Œ. (ํ™”๋ฉด์„ ์ ์œ ํ•˜๊ณ  ์žˆ๋‹ค)

# Background

  • ๋ฉ”๋ชจ๋ฆฌ์— ์•ฑ์ด ์ ์žฌ๋˜์–ด์žˆ์Œ. (ํ™”๋ฉด์„ ์ ์œ ํ•˜์ง€ ์•Š๋Š”๋‹ค)
  • Background๋กœ ๋“ค์–ด๊ฐ€๋ฉด ์•ฑ์ด ์ข…๋ฃŒ๋˜์—ˆ๋‹ค๊ณ  ๋ณธ๋‹ค.

# Background - Running

  • ๋ฐฑ๊ทธ๋ผ์šด๋“œ์ด์ง€๋งŒ, ๋„คํŠธ์›Œํฌ ํ†ต์‹ ์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ, ํ˜น์€ ์ž„์‹œ์ €์žฅ ๋“ฑ ๋งˆ์ง€๋ง‰ ํ•˜๋‚˜์˜ ํ•จ์ˆ˜๋งŒ ํ˜ธ์ถœ๊ฐ€๋Šฅํ•˜๋‹ค.
  • ์• ํ”Œ ๋ณด์•ˆ์ง€์นจ์ƒ Background running๋˜๋Š”๊ฒƒ์€ ๊ต‰์žฅํžˆ ์ œํ•œ์ ์ด๋‹ค. ์•ฑ์„ Background๋กœ ๋ณด๋‚ด๊ณ  5๋ถ„๊ฐ€๋Ÿ‰๋งŒ Running์ƒํƒœ๋ฅผ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ๋…น์Œ, gps, ์Œ์•… ๋“ฑ์€ background์—์„œ๋„ ๋™์ž‘ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ๋งˆ์ง€๋ง‰ ํ˜ธ์ถœํ•œ ํ•จ์ˆ˜๊ฐ€ ์‹คํ–‰ ์™„๋ฃŒ๋˜๋ฉด Suspend์ƒํƒœ๋กœ ๋ฐ”๋€๋‹ค.

# Background - Suspend

  • ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ๋Œ€๊ธฐ์ƒํƒœ์— ์žˆ๋Š” ์•ฑ์„ ๋งํ•œ๋‹ค. (์•„๋ฌด๋Ÿฐ ๋™์ž‘์„ ํ•˜์ง€ ์•Š๋Š” ๋Œ€๊ธฐ)
  • Suspend ์ƒํƒœ์ธ ์•ฑ์ด ๋งŽ์•„์ ธ์„œ, ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๋ถ€์กฑํ•ด์ง€๋ฉด OS์—์„œ ์ž๋™์œผ๋กœ Not Running ์ƒํƒœ๋กœ ๋ฐ”๊ฟ”๋ฒ„๋ฆฐ๋‹ค.

 

 

# AppDelegate Method (iOS12๊นŒ์ง€)

iOS13์ด์ „

์‹ค์„  - ์‚ฌ์šฉ์ž ๋™์ž‘,  ์ ์„  - ์‹œ์Šคํ…œ ๋™์ž‘

(๋งŒ์•ฝ ์‚ฌ์šฉํ•˜๋ ค๋ฉด SceneDelegate๋ฅผ ์‚ญ์ œํ•˜๊ณ , info.plist์—์„œ๋„ Scene๊ด€๋ จ ํ”„๋กœํผํ‹ฐ๋ฅผ ์‚ญ์ œํ•˜๋ฉด ๋œ๋‹ค.)

(iOS12๊นŒ์ง€)UIKit์€ ๋ชจ๋“  LifeCycle์„ UIApplicationDelegate ๊ฐ์ฒด์— ์ „๋‹ฌํ•œ๋‹ค. AppDelegate๋Š” ์•ฑ์˜ ๋ชจ๋“  window๋ฅผ ๊ด€๋ฆฌํ•˜๊ฒŒ ๋œ๋‹ค.

Not Running ์ƒํƒœ์˜ ์•ฑ์„ ์‹คํ–‰์‹œํ‚ฌ๋•Œ ํ˜ธ์ถœ

application(_: DidFinishLaunchingWithOptions:)

  • ์•ฑ์„ ์‹คํ–‰ํ•˜๊ณ  ์•ฑ ์ดˆ๊ธฐํ™”๋ฅผ ์™„๋ฃŒํ•˜๊ณ  ๋‚œ ์งํ›„์— ํ˜ธ์ถœ๋œ๋‹ค.

Active์ƒํƒœ๋กœ ๋ฐ”๋€Œ๊ณ  ๋‚˜์„œ  ํ˜ธ์ถœ

applicationDidBecomeActive:

 

InActive์ƒํƒœ๋กœ ๋ฐ”๋€Œ๊ธฐ ์ง์ „ ํ˜ธ์ถœ

applicationWillResignActive:

 

Background ์ƒํƒœ๋กœ ๋ฐ”๋€Œ๊ณ  ๋‚˜์„œ ํ˜ธ์ถœ

applicationDidEnterBackground:

 

Foreground ์ƒํƒœ๋กœ ๋ฐ”๋€Œ๊ธฐ  ์ง์ „ ํ˜ธ์ถœ

applicationWillEnterForeground:

 

 

Not Running ์ƒํƒœ๋กœ ๋ฐ”๋€” ๋•Œ ํ˜ธ์ถœ

applicationWillTerminate:

  • ์ด ๋ฉ”์†Œ๋“œ๋Š” ์•ฑ์„ ์ข…๋ฃŒํ•ด์ฃผ๊ณ , ๋ฉ”๋ชจ๋ฆฌ์—์„œ ์ œ๊ฑฐํ•ด์ค€๋‹ค๋Š”๊ฒƒ์„ ์•Œ๋ ค์ค€๋‹ค. ์‚ฌ์šฉ์ž ๋ฐ์ดํ„ฐ ์ €์žฅ, ๊ณต์œ  ๋ฆฌ์†Œ์Šค ํ•ด์ œ๋“ฑ์˜ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋ฉฐ ์ตœ์ข…์ ์œผ๋กœ ๋ฐ˜ํ™˜ํ•˜๋Š”๋ฐ ์•ฝ 5์ดˆ์ •๋„๊ฐ€ ๊ฑธ๋ฆฐ๋‹ค.
  • ์ผ๋ฐ˜์ ์œผ๋กœ ์‚ฌ์šฉ์ž๊ฐ€ ์•ฑ์„ ์ข…๋ฃŒํ• ๋•Œ ํ˜ธ์ถœ๋˜์ง€๋Š” ์•Š๋Š”๋‹ค. ์•ฑ์ด ๋ฐฑ๊ทธ๋ผ์šด๋“œ๋กœ ์ด๋™ํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋ฉฐ, ์‹œ์Šคํ…œ์ด ํŠน์ • ์ด์œ ๋กœ ์•ฑ์„ ์ข…๋ฃŒํ•ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ์—์„œ ํ˜ธ์ถœ๋  ์ˆ˜ ์žˆ๋‹ค.
  • ๋ฐฑ๊ทธ๋ผ์šด๋“œ๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š๋Š” ์•ฑ์ด๋ผ๋ฉด ์‚ฌ์šฉ์ž๊ฐ€ ์ข…๋ฃŒํ• ๋•Œ ์ด ๋ฉ”์†Œ๋“œ๋Š” ํ•ญ์ƒ ์‹คํ–‰๋œ๋‹ค.

 

# iOS13์ดํ›„์— AppDelegate์— ์ถ”๊ฐ€๋œ ๋ฉ”์†Œ๋“œ

1. application(... configurationForConnecting: )  ->>>>   scene์„ ๋งŒ๋“ค ๋•Œ ๊ตฌ์„ฑ ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฉ”์†Œ๋“œ

2. application(_ : didDiscardSceneSessions:) ->>>> App switcher๋ฅผ ํ†ตํ•ด scene์„ ๋‹ซ์„๋•Œ ํ˜ธ์ถœ๋œ๋‹ค.

 

 

 

 

# Scene Delegate Method (iOS13์ดํ›„)

iOS 13๋ถ€ํ„ฐ๋Š” Scene์ด๋ผ๋Š” ๊ฐœ๋…์ด ๋„์ž…๋˜์—ˆ๋‹ค. ํ•˜๋‚˜์˜ ์•ฑ์ด ์—ฌ๋Ÿฌ๊ฐœ์˜ Scene์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด๋•Œ ๊ฐ Scene๋งˆ๋‹ค life Cycle์ด ์กด์žฌํ•˜๊ฒŒ ๋œ๋‹ค. 

Scene์€ UI ๋ฐ ์ปจํ…์ธ ์˜ ๋ฐฐ๊ฒฝ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š”๊ฒƒ์„ ๋งํ•˜๋ฉฐ, UI์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” windows์™€ ViewController๊ฐ€ ๋‚ด๋ถ€์— ํฌํ•จ๋œ๋‹ค.

Scene๋“ค์€ ๊ฐ™์€ ๋ฉ”๋ชจ๋ฆฌ์™€ ์•ฑ ํ”„๋กœ์„ธ์Šค ๊ณต๊ฐ„์„ ๊ณต์œ ํ•˜๋ฉฐ, ์„œ๋กœ ๋™์‹œ์— ์‹คํ–‰๋˜๋Š”๋ฐ ๊ฒฐ๊ณผ์ ์œผ๋กœ ํ•˜๋‚˜์˜ ์•ฑ์€ ์—ฌ๋Ÿฌ๊ฐœ์˜ Scene๊ณผ SceneDelegate ๊ฐ์ฒด๋ฅผ ํ™œ์„ฑํ™” ํ•  ์ˆ˜ ์žˆ๋‹ค. (๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— iOS์—์„œ Split Veiw๋ฅผ ์ด์šฉํ•˜์—ฌ ๋‹ค์ค‘ ์•ฑ์„ ๋นŒ๋“œํ•  ์ˆ˜ ์žˆ๋‹ค.)

  • Scene Delegate๊ฐ€ ์ƒ๊ธฐ๋ฉด์„œ Not Running๋‹จ๊ณ„๊ฐ€ ์‚ฌ๋ผ์กŒ๋‹ค.
  • Scene์€ ์„ ํƒ ๊ฐ€๋Šฅํ•œ ๊ธฐ๋Šฅ์ด๋‹ค.
  •  

SceneDelegate๋กœ ๋Œ€์ฒด๋œ ๋ฉ”์†Œ๋“œ๋“ค
SceneDelegate

 

 

 

 

https://developer.apple.com/documentation/uikit/app_and_environment/managing_your_app_s_life_cycle/

 

 

Apple Developer Documentation

 

developer.apple.com

 

Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.