티스토리 뷰

Tech/iOS

iOS Application lifecycle

Ellie Kim 2019. 4. 5. 15:20

앱 라이프 사이클에 대해서 정리해보자.

앱 라이프 사이클에는 5가지 상태가 존재합니다.

- Not running

Application이 아직 시작되지 않았거나 실행 중이었는데 시스템에 의해 종료된 상태입니다.

- Inactive

Application이 Foreground에서 실행중이지만 어떠한 이벤트를 수신하지 않는 상태입니다.

UIEvent를 받지 않으므로 앱과 상호작용 할 수 없습니다.

전화 또는 메시지가 수신될 때 발생할 수 있습니다.

- Active

Application이 Foregroun에서 실행중이며 이벤트를 수신하는 상태입니다.

UIEvent를 받으므로 앱과 상호작용이 가능합니다.

- Background

Application이 Background에서 실행중이고 코드가 실행 중입니다.

- Suspended 

Application이 Background에 있지만 실행 중인 코드가 없는 상태입니다.

시스템은 Application을 자동으로 Suspended로 이동시킵니다.

(메모리가 부족한 경우 시스템은 Foreground에 실행되는 여유 공간을 확보하기 위해 Suspended상태의 Application을 제거할 수 있습니다.)

일반적으로 Background상태에서 5초가 지나면 Suspended상태로 전환됩니다. 

 

 

각각의 상황에 맞게 메서드가 호출되며 상황에 맞는 코드를 작성해 줄 수 있습니다.

1. application:didFinishLaunchingWithOptions

Application 윈도우가 표시되기 전에 호출됩니다.

앱이 사용자에게 표시되기 전에 최종 초기화를 수행할 수 있습니다.

2. applicationDidBecomeActive

Inactive에서 Active 한 상태로 갈 때 호출됩니다.

마지막 준비 ㄱ ㄱ Use this method for any last minute preparation.

3. applicationWillResignActive

Active에서 Inactive 한 상태로 갈 때 호출됩니다. (Foreground를 떠날 때)

4. applicationDidEnterBackground

Inactive에서 Background 한 상태로 갈 때 호출됩니다.

앱이 언제든지 Suspended상태로 갈 수 있습니다.

5. applicationWillEnterForeground

Background에서 Foreground상태로 갈때 호출됩니다.

하지만 아직 Active 상태는 아닙니다.

+ applicationWillTerminate

이 메서드는 앱이 곧 종료될 예정임을 알려주기 위해 호출됩니다.

최종적으로 처리해줘야 하는 코드를 여기에 작성합니다.

만약 앱이 suspended되면 이 메서드는 호출되지 않습니다.

 


https://developer.apple.com/library/archive/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TheAppLifeCycle/TheAppLifeCycle.html

 

The App Life Cycle

The App Life Cycle Apps are a sophisticated interplay between your custom code and the system frameworks. The system frameworks provide the basic infrastructure that all apps need to run, and you provide the code required to customize that infrastructure a

developer.apple.com

 

'Tech > iOS' 카테고리의 다른 글

iOS NavigationBar 색 변경  (0) 2019.07.11
UIImageView ContentMode 종류  (0) 2019.04.29
iOS 뷰 컨트롤러 생명주기  (0) 2019.04.04
Protocol에 class선언해주기  (0) 2019.02.05
iOS AnimationOptions  (0) 2019.01.16
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/06   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
글 보관함