IOS Application Life Cycle

ansu jain
2 min readSep 4, 2017

--

Every iOS Developer, should know application lifecycle. Application lifecycle helps to understand overall app behaviour.

The main point of entry into iOS apps is UIApplicationDelegate. UIApplicationDelegate is a protocol that your app has to implement to get notified about user events such as app launch, app goes into background or foreground, app is terminated, a push notification was opened, etc.

Application Lifecycle Example:

When an iOS app is launched the first thing called is

application: willFinishLaunchingWithOptions:-> Bool. This method is intended for initial application setup. Storyboards have already been loaded at this point but state restoration hasn’t occurred yet.

Launch

  • application: didFinishLaunchingWithOptions: -> Bool is called next. This callback method is called when the application has finished launching and restored state and can do final initialization such as creating UI.
  • applicationWillEnterForeground: is called after application: didFinishLaunchingWithOptions: or if your app becomes active again after receiving a phone call or other system interruption.
  • applicationDidBecomeActive: is called after applicationWillEnterForeground: to finish up the transition to the foreground.

Termination

  • applicationWillResignActive: is called when the app is about to become inactive (for example, when the phone receives a call or the user hits the Home button).
  • applicationDidEnterBackground: is called when your app enters a background state after becoming inactive. You have approximately five seconds to run any tasks you need to back things up in case the app gets terminated later or right after that.
  • applicationWillTerminate: is called when your app is about to be purged from memory. Call any final cleanups here.

Both application: willFinishLaunchingWithOptions: and application: didFinishLaunchingWithOptions: can potentially be launched with options identifying that the app was called to handle a push notification or url or something else. You need to return true if your app can handle the given activity or url.

Knowing your app’s lifecycle is important to properly initialize and set up your app and objects. You don’t have to run everything in application: didFinishLaunchingWithOptions, which often becomes a kitchen sink of setups and initializations of some sort.

I hope, above tutorial will help to clear the concepts of application lifecycle.

--

--