Managing Your App's Life Cycle

Panther·2021년 3월 23일
0

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

"Respond to system notifications when your app is in the foreground or background, and handle other significant system-related events."

앱이 포어그라운드 혹은 백그라운드에 진입할 때 시스템 노티피케이션에 응답합니다. 그리고 다른 중요한 시스템 관련 이벤트를 처리합니다.

Overview

앱의 현재 상태는 무엇을 할 수 있고 무엇을 할 수 없는지 보여줍니다. 포어그라운드 앱은 사용자의 집중을 끌고 있는 것으로, 시스템 리소스(CPU 포함) 상 우선순위를 가집니다. 반대로 백그라운드 앱은 가능한 가장 적은 작동만 해야 합니다. 앱의 상태 변화에 따른 움직임을 적용해줘야 합니다.

앱의 상태가 변화하면 UIKit은 적절한 딜리게이트 객체 메소드를 호출하는 것을 통해 앱의 상태 변화를 알려줍니다.

Respond to Scene-Based Life-Cycle Events

앱이 씬(scene)을 지원하는 경우 UIKit은 각각에게 분리된 생명주기 이벤트를 전달합니다. 씬은 기기에서 작동하는 앱의 UI 인스턴스를 나타냅니다. 사용자는 여러 앱이 갖는 각각의 씬을 생성할 수 있고 각각을 보여주거나 숨길 수 있습니다. 각각의 앱이 갖는 씬은 서로 다른 생명주기를 갖고 있기 때문에 실행 상태가 다를 수 있습니다. 예를 들어 하나의 씬은 포어그라운드일지라도 하나는 백그라운드 혹은 정지된 상태일 수 있습니다.

아래 이미지가 씬이 갖는 상태 변화를 보여주고 있습니다.

씬 전환을 사용할 때면 아래와 같은 수행이 이뤄집니다.

  • 앱에 씬을 연결할 때 씬의 초기 UI를 설정하고 씬에서 요구하는 데이터를 로드합니다.
  • 포어그라운드 활성 상태로 전환할 때, UI를 설정하고 사용자와 상호작용할 준비를 합니다. Preparing Your UI to Run in the Foreground 내용을 살펴보시기 바랍니다.
  • 포어그라운드 활성 상태에서 빠져나오면, 데이터를 저장하고 앱의 행동을 멈춥니다. Preparing Your UI to Run in the Background 내용을 살펴보시기 바랍니다.
  • 백그라운드 상태로 진입하게 되면 중요한 작업을 멈추면서 가능한 메모리를 해제시키고 앱의 스냅샷을 준비합니다. Preparing Your UI to Run in the Background. 내용을 살펴보시기 바랍니다.
  • 씬의 연결이 끊어지면, 씬과 관련있는 모든 리소스를 지웁니다.
  • 씬과 연관된 이벤트와 더불어 UIApplicationDelegate 객체를 사용해 앱의 launch에 반응할 수 있도록 해야 합니다. Responding to the Launch of Your App 내용을 살펴보시기 바랍니다.

Preparing Your UI to Run in the Foreground
https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_foreground
https://velog.io/@panther222128/Preparing-Your-UI-to-Run-in-the-Foreground

Preparing Your UI to Run in the Background
https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background
https://velog.io/@panther222128/Preparing-Your-UI-to-Run-in-the-Background

Responding to the Launch of Your App.
https://developer.apple.com/documentation/uikit/app_and_environment/responding_to_the_launch_of_your_app
https://velog.io/@panther222128/Responding-to-the-Lauch-of-Your-App

Respond to App-Based Life-Cycle Events

iOS 12와 이전 버전, 그리고 씬을 지원하지 않는 앱은 UIKit이 모든 생명주기 이벤트를 UIApplicationDelegate 객체에 전달합니다. 앱 딜리게이트는 앱의 모든 창들을 다루며, 각각의 화면이 나타나는 바를 포함합니다. 결과적으로 앱의 상태 전환은 앱의 전체 UI에 영향을 미치고, 이는 외부화면에 있는 내용에도 포함됩니다.

아래 이미지는 앱 딜리게이트 객체가 관여하는 상태 전환을 보여주고 있습니다.

  • launch 시 앱의 데이터 구조와 UI를 초기화합니다.
  • 활성화에서 UI 설정을 마치고 사용자와 상호작용할 준비를 합니다.
  • 비활성화 데이터를 저장하고 앱의 행동을 멈춥니다.
  • 백그라운드 상태로 진입 시 중요 작업수행을 멈추고 가능한 많은 메모리를 해제시키며, 스냅샷을 준비합니다.
  • 종료 시 모든 작업을 즉시 마치고 리소스를 방출합니다. appilcationWillTerminate(_:) 메소드를 참고하면 좋습니다.

Respond to Other Significant Events

생명주기 이벤트를 처리하는 것과 더불어 앱은 아래 테이블에 나와있는 이벤트를 처리할 준비가 되어 있어야 합니다. 아래와 같은 대부분의 이벤트를 처리하려면 UIApplicationDelegate 객체를 사용하시기 바랍니다. 몇 가지 경우 앱의 다른 부분에서 반응하는 것을 허용할 수 있도록 노티피케이션을 사용해 처리할 수도 있습니다.

Memory warnings앱의 메모리 사용이 지나치게 높을 때 받게됩니다. 앱 사용에서 메모리의 양을 줄여야 합니다. Responding to Memory Warnings를 살펴보시기 바랍니다.
Protected data becomes available/unavailable사용자가 기기를 잠그거나 해제할 때 받습니다. applicationProtectedDataDidBecomeAvailable(:), applicationProtectedDataWillBecomeUnavailable(:)을 살펴보시기 바랍니다.
Handoff tasksNSUserActivity 객체가 처리될 필요가 있을 때 받습니다. application(_:didUpdate:)를 살펴보시기 바랍니다.
Time changes이동통신사가 시간을 업데이트할 때와 같은 이유로 시간을 변경해야 할 때 받습니다. applicationSignificantTimeChange(_:)를 살펴보시기 바랍니다.
Open URLs앱이 리소스를 열고자할 때 받습니다. application(_:open:options:)를 살펴보시기 바랍니다.

Topics


Behavioral Events

Responding to Memory Warnings

시스템에 의해 메모리 공간을 비우도록 요청받은 경우 메모리 공간을 비웁니다.

https://developer.apple.com/documentation/uikit/app_and_environment/managing_your_app_s_life_cycle/responding_to_memory_warnings
https://velog.io/@panther222128/Responding-to-Memory-Warnings


See Also


Life Cycle

Responding to the Launch of Your App

앱의 데이터 구조를 초기화하고, 앱의 실행을 준비합니다. 그리고 시스템으로부터 모든 launch 타임 요청에 반응합니다.

https://developer.apple.com/documentation/uikit/app_and_environment/responding_to_the_launch_of_your_app
https://velog.io/@panther222128/Responding-to-the-Lauch-of-Your-App

UIApplication

iOS에서 작동하는 앱에 대한 컨트롤과 조정의 중심점입니다.

https://developer.apple.com/documentation/uikit/uiapplication
https://velog.io/@panther222128/UIApplication-and-App-Delegate

Scenes

앱의 여러 UI 인스턴스들을 동시에 관리하고, 리소스들을 UI의 적합한 인스턴스로 보냅니다.

https://developer.apple.com/documentation/uikit/app_and_environment/scenes
https://velog.io/@panther222128/Scenes


0개의 댓글