๊ณต๋ถ€ ์—ฐ์Šต์žฅ :-)

AppDelegate methods by App lifecycle

|

์•ฑ ๋ผ์ดํ”„์‚ฌ์ดํด์— ๋”ฐ๋ฅธ AppDelegate methods ์ •๋ฆฌ Strategies for Handling App State Transitions ์ฐธ๊ณ , ๊ฐ„๋‹จ๋ฒˆ์—ญ๊ณผ ์ •๋ฆฌ

  • ๋Œ€๋ถ€๋ถ„์˜ ์ƒํƒœ๋ณ€ํ™”๋Š” AppDelegate๊ฐ์ฒด์˜ ๋ฉ”์†Œ๋“œ ํ˜ธ์ถœ์„ ๊ฑฐ์นœ๋‹ค.
  • AppDelegate.swift ํŒŒ์ผ์—๋Š” ์•ฑ์˜ ์ƒํƒœ์— ๋”ฐ๋ผ ์‹คํ–‰๋˜๋Š” ํ•จ์ˆ˜๋“ค์ด ์ •์˜๋˜์–ด ์žˆ๋‹ค.
  • ์•ฑ์˜ ์ƒํƒœ์— ๋”ฐ๋ผ ์‹คํ–‰๋˜๋Š” delegate ํ•จ์ˆ˜๋“ค์ด ์ •์˜๋˜์–ด ์žˆ๊ธฐ๋•Œ๋ฌธ์— ํ•จ์ˆ˜์•ˆ์— ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑ ํ•จ์œผ๋กœ์จ ์•ฑ์˜ ํŠน์ • ์ƒํƒœ์—์„œ ๋™์ž‘ํ•˜๋Š” ๋กœ์ง์„ ๊ตฌํ˜„ ํ•  ์ˆ˜ ์žˆ๋‹ค.
application(_:didFinishLaunching:) - ์•ฑ์ด ์ฒ˜์Œ ์‹œ์ž‘๋  ๋•Œ ์‹คํ–‰
applicationWillResignActive: - ์•ฑ์ด active ์—์„œ inactive๋กœ ์ด๋™๋  ๋•Œ ์‹คํ–‰(foreground)
applicationDidEnterBackground: - ์•ฑ์ด background ์ƒํƒœ์ผ ๋•Œ ์‹คํ–‰
applicationWillEnterForeground: - ์•ฑ์ด background์—์„œ foreground๋กœ ์ด๋™ ๋ ๋•Œ ์‹คํ–‰ (์•„์ง foreground์—์„œ ์‹คํ–‰์ค‘์ด์ง„ ์•Š์Œ)
applicationDidBecomeActive: - ์•ฑ์ด active์ƒํƒœ๊ฐ€ ๋˜์–ด ์‹คํ–‰ ์ค‘(foreground)
applicationWillTerminate: - ์•ฑ์ด ์ข…๋ฃŒ๋  ๋•Œ ์‹คํ–‰
  • application:willFinishLaunchingWithOptions:
    • ์•ฑ์„ ์‹คํ–‰ํ•  ๋•Œ ์ตœ์ดˆ๋กœ ์‹คํ–‰ํ•  ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ์ข‹์Œ.
    • ์•ฑ์„ ์‹คํ–‰ํ•  ๋•Œ ํ•„์š”ํ•œ, ์•ฑ ๋ฒˆ๋“ค์ด๋‚˜ iCloud ์ปจํ…Œ์ด๋„ˆ์— ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์™€์„œ ์„ค์ •ํ• ๋•Œ ์‚ฌ์šฉ
  • application:didFinishLaunchingWithOptions:
  • ์•ฑ์˜ ํ™”๋ฉด์ด ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ง€๊ธฐ ์ง์ „์— ์ตœ์ข… ์ดˆ๊ธฐํ™” ์ž‘์—…์„ ์ง„ํ–‰
  • applicationDidBecomeActive: ์•ฑ์ด ์ด์ œ Foreground๋กœ ๊ฐˆ ๊ฒƒ. ์ตœ์ข… ์ค€๋น„์ž‘์—….
  • applicationWillResignActive:
    • ์•ฑ์ด Foreground์—์„œ ๋‹ค๋ฅธ ์ƒํƒœ๋กœ ์ „ํ™˜์ด ๋ ๊ฒƒ์ž„์„ ์•Œ๋ ค์ค๋‹ˆ๋‹ค. ์•ฑ์ด ์ž ์ž ํ•œ(quiescent) ์ƒํƒœ๋กœ ๋ณ€ํ™˜๋˜๋Š” ์ž‘์—…์„ ์—ฌ๊ธฐ์„œ ์ง„ํ–‰ํ•˜์„ธ์š”.
    • Alert-based interruptions์œผ๋กœ ์ธํ•ด ์•ฑ์˜ ์ปจํŠธ๋กค์ด ์ผ์‹œ์ ์œผ๋กœ ์ค‘๋‹จ๋  ์ˆ˜ ์žˆ๋‹ค. ์•ฑ์€ foreground์ƒํƒœ์—์„œ ๊ณ„์† ๋™์ž‘ํ•˜์ง€๋งŒ, touch event๋ฅผ ๋ฐ›์„ ์ˆ˜ ์—†๋Š” ์ƒํƒœ์ด๋‹ค. (It does continue to receive notifications and other types of events, such as accelerometer events, though.)
    • ์ด๋Ÿฌํ•œ ์ƒํƒœ์— ๋Œ€์ฒ˜ํ•˜๊ธฐ์œ„ํ•ด applicationWillResignActive๋ฅผ ๊ตฌํ˜„ํ•ด์•ผํ•จ
      • Save data and any relevant state information.
      • Stop timers and other periodic tasks.
      • Stop any running metadata queries.
      • Do not initiate any new tasks.
      • Pause movie playback (except when playing back over AirPlay).
      • Enter into a pause state if your app is a game.
      • Throttle back OpenGL ES frame rates.
      • Suspend any dispatch queues or operation queues executing non-critical code. - (You can continue processing network requests and other time-sensitive background tasks while inactive.)
  • applicationWillEnterForeground:
    • ์•ฑ์ด Background์—์„œ ๋‹ค์‹œ Foreground๋กœ ๋Œ์•„์˜ค๊ฒŒ ๋  ๊ฒƒ์ž„์„ ์•Œ๋ ค์คŒ. ์•„์ง ์•ฑ์ด Active์ƒํƒœ๋Š” ์•„๋‹˜.
    • ์ด ํ•จ์ˆ˜๋Š” applicationWillResignActive:๋Š” ๋ฐ˜๋Œ€์˜ ์ƒํƒœ์ผ๋•Œ ํ˜ธ์ถœ๋˜๋Š”๋ฐ, ์ด๋•Œ๋Š” reactivation์— ํ•„์š”ํ•œ ๋™์ž‘์„ ๊ตฌํ˜„ํ•ด์•ผํ•œ๋‹ค.
      • restart timers, resume dispatch queues, and throttle up OpenGL ES frame rates again. However, games should not resume automatically; they should remain paused until the user chooses to resume them.
  • applicationDidEnterBackground: ์•ฑ์ด Background๋กœ ๋Œ์•„๊ฐ. ๊ทธ๋ฆฌ๊ณ  ์–ธ์ œ๋“ ์ง€ Suspended์ƒํƒœ๋กœ ๋ณ€ํ™˜์ด ๋  ์ˆ˜ ์žˆ๋‹ค.
  • applicationWillTerminate: ์•ฑ์ด ์ข…๋ฃŒ๋  ๊ฒƒ์ž„์„ ์•Œ๋ ค์คŒ. ๋งŒ์•ฝ ์•ฑ์ด Suspended์ƒํƒœ๋ผ๋ฉด ์ด ๋ฉ”์†Œ๋“œ๋Š” ํ˜ธ์ถœ๋˜์ง€ ์•Š๋Š”๋‹ค.

Responding to Temporary Interruptions

  • Notifications that display a banner do not deactivate your app in the way that alert-based notifications do. Instead, the banner is laid along the top edge of your app window and your app continues receive touch events as before. However, if the user pulls down the banner to reveal the notification center, your app moves to the inactive state just as if an alert-based interruption had occurred. Your app remains in the inactive state until the user dismisses the notification center or launches another app. At this point, your app moves to the appropriate active or background state. The user can use the Settings app to configure which notifications display a banner and which display an alert.

  • Pressing the Sleep/Wake button is another type of interruption that causes your app to be deactivated temporarily. When the user presses this button, the system disables touch events, moves the app to the background, sets the value of the appโ€™s applicationState property to UIApplicationStateBackground, and locks the screen. A locked screen has additional consequences for apps that use data protection to encrypt files.

What to Do When Your App Enters the Foreground

Note: The UIApplicationWillEnterForegroundNotification notification is also available for tracking when your app reenters the foreground. Objects in your app can use the default notification center to register for this notification.

Comments