Skip to content

Latest commit

ย 

History

History
48 lines (34 loc) ยท 2.95 KB

foreground,background.md

File metadata and controls

48 lines (34 loc) ยท 2.95 KB

์•ฑ์ด foreground์— ์žˆ์„ ๋•Œ์™€ background์— ์žˆ์„ ๋•Œ ์–ด๋–ค ์ œ์•ฝ์‚ฌํ•ญ์ด ์žˆ๋‚˜์š”?


๋„์›€์„ ์ค€ ์ข‹์€ ๋ธ”๋กœ๊ทธ

์‚ฌ์ „ ์ง€์‹

  • foreground ์ƒํƒœ์˜ ์•ฑ์€ ์‚ฌ์šฉ์ž๊ฐ€ ๋ณด๊ณ  ์žˆ๋Š” ํ™”๋ฉด์ด๋‹ค. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— CPU๋ฅผ ๋น„๋กฏํ•œ ์‹œ์Šคํ…œ ์ž์›์˜ ์šฐ์„ ์ˆœ์œ„๊ฐ€ ๋†’์€ ์ƒํƒœ

  • background ์ƒํƒœ๋ž€ ์•ฑ์ด ํ™ˆํ™”๋ฉด์— ๋“ค์–ด๊ฐ€์„œ ์‚ฌ์šฉ์žํ•œํ…Œ ๋ณด์ด์ง€ ์•Š๋Š” ์ƒํƒœ์ด๋‹ค.

    ๐Ÿ’ก ์•ฑ์ด background ์ƒํƒœ๊ฐ€ ๋˜์–ด๋„ ๊ณ„์† ์‹คํ–‰ํ•ด์•ผ ๋  ๋•Œ๊ฐ€ ์กด์žฌํ•œ๋‹ค.
    โ–ถ๏ธ ์Œ์•… ์•ฑ์„ ์ด์šฉํ•˜์—ฌ ๋…ธ๋ž˜๋ฅผ ๋“ฃ๋Š” ๊ฒฝ์šฐ์ฒ˜๋Ÿผ ๋‹ค๋ฅธ ์–ดํ”Œ์„ ์‚ฌ์šฉํ•˜๋”๋ผ๋„ ๋ฉˆ์ถ”๋ฉด ์•ˆ๋˜๋Š” ์•ฑ๋“ค

  • App State(์•ฑ ์ƒํƒœ)

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

    • Inactive: ์•ฑ์ด foreground ์ƒํƒœ์ด๊ธฐ๋Š” ํ•˜๋‚˜ ์ด๋ฒคํŠธ๋ฅผ ๋ฐ›์ง€ ๋ชปํ•œ ์ƒํƒœ

    • Active: ์•ฑ์ด foreground์—์„œ ์‹คํ–‰ ์ค‘์ด๋ฉฐ ์ด๋ฒคํŠธ๋ฅผ ๋ฐ›์•˜์„ ๋•Œ์˜ ์ƒํ™ฉ

    • Background: ์•ฑ์ด background์— ์žˆ์œผ๋ฉฐ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ์žˆ๋Š” ์ƒํƒœ

    • Suspended: ์•ฑ์ด background์ด๋ฉฐ ์•ฑ์ด ๋ฉ”๋ชจ๋ฆฌ์— ๋‚จ์•„ ์žˆ๊ธด ํ•˜๋‚˜ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ์žˆ์ง€ ์•Š์€ ์ƒํƒœ

  • App Launch Cycle

    • ์œ„์—์„œ ์–ธ๊ธ‰ํ•œ ๊ฐ App State ์˜ ์ƒํƒœ ๋ณ€ํ™”๋Š” Delegate ๋ฉ”์„œ๋“œ๋“ค์˜ ํ˜ธ์ถœ์ด ๋™๋ฐ˜๋œ๋‹ค.

    • ๊ฐ ๋ฉ”์„œ๋“œ๋“ค์€ ์•ฑ์˜ ์ƒํƒœ ๋ณ€ํ™”์— ๋Œ€ํ•ด ์ ์ ˆํ•œ ๋ฐฉ์‹์œผ๋กœ ๋Œ€์‘ํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐํšŒ๋ฅผ ๊ฐ€์ง€๊ฒŒ ํ•ด์ค€๋‹ค

      Method Description
      application(_:didFinishLaunching:) ์•ฑ์ด ์ฒ˜์Œ ์‹œ์ž‘๋  ๋•Œ ์‹คํ–‰
      applicationWillResignActive: ์•ฑ์ด Active ์—์„œ Inactive๋กœ ์ด๋™๋  ๋•Œ ์‹คํ–‰
      applicationDidEnterBackground: ์•ฑ์ด background ์ƒํƒœ์ผ ๋•Œ ์‹คํ–‰
      applicationWillEnterForeground: ์•ฑ์ด background์—์„œ foreground๋กœ ์ด๋™ ๋ ๋•Œ ์‹คํ–‰ (์•„์ง foreground์—์„œ ์‹คํ–‰์ค‘์ด์ง„ ์•Š์Œ)
      applicationDidBecomeActive: ์•ฑ์ด Active์ƒํƒœ๊ฐ€ ๋˜์–ด ์‹คํ–‰ ์ค‘์ผ ๋•Œ
      applicationWillTerminate: ์•ฑ์ด ์ข…๋ฃŒ๋  ๋•Œ ์‹คํ–‰

Answer

  • foreground์— ์žˆ์„ ๋•Œ์—๋Š” ๋ฉ”๋ชจ๋ฆฌ ๋ฐ ๊ธฐํƒ€ ์‹œ์Šคํ…œ ๋ฆฌ์†Œ์Šค์— ๋Œ€ํ•ด์„œ background๋ณด๋‹ค ๋†’์€ ์šฐ์„ ์ˆœ์œ„๋ฅผ ๊ฐ€์ง€๋ฉฐ ์‹œ์Šคํ…œ์€ ์ด๋Ÿฌํ•œ ๋ฆฌ์†Œ์Šค๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•„์š”์— ๋”ฐ๋ผ background ์•ฑ์„ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค.
  • background์— ์žˆ์„ ๋•Œ์—๋Š” ๊ฐ€๋Šฅํ•œ ์ ์€ ๋ฉ”๋ชจ๋ฆฌ๊ณต๊ฐ„์„ ์‚ฌ์šฉํ•ด์•ผํ•˜๋ฉฐ(์‹œ์Šคํ…œ ๋ฆฌ์†Œ์Šค ํ•ด์ œ, ๋ฉ”๋ชจ๋ฆฌ์—์„œ ํ•ด์ œ ํ›„ ๋ฐ์ดํ„ฐ๋ฅผ ๋””์Šคํฌ์— ์ž‘์„ฑ) ์šฐ์„ ์ˆœ์œ„์— ์˜ํ•ด foreground task๋ณด๋‹ค ๋” ๋‚ฎ์€ ์ž์›์„ ํ• ๋‹น๋ฐ›์Šต๋‹ˆ๋‹ค.