iOS Application Life Cycle

Every iOS developer needs to be familiar with the application lifecycle. Understanding the application lifecycle can help with app behavior in general.

The UIApplicationDelegate is the primary point of access to iOS apps. Your program must conform to the UIApplicationDelegate protocol in order to receive notifications when certain user actions occur, like the launch of your app, its foreground or background switching, its termination, the opening of a push notification, etc.

When an iOS app launches, the first function called is;

application: willFinishLaunchingWithOptions: This approach is designed for initial application setup. At this moment, storyboards are already loaded, but state restoration has not yet occurred.

Launch

  • applicationdidFinishLaunchingWithOptions: This callback method is called when the application has finished launching and restoring state and can perform a final initialization like creating the user interface.
  • applicationWillEnterForeground: If your app becomes active again after being interrupted by a phone call or another system interruption.
  • applicationDidBecomeActive: to complete the transition to the foreground.

Termination

  • applicationWillResignActive: When the app is about to become inactive, this command is issued (for example, when the phone receives a call or the user hits the Home button).
  • applicationDidEnterBackground: When your app becomes inactive, it enters the background state. You have about five seconds to complete any tasks necessary to backup your data in case the app is terminated later or immediately after that.
  • applicationWillTerminate: When your app is about to be purged from memory, this method is called. Any final cleanups should be done here.

Both application: willFinishLaunchingWithOptions: and application: didFinishLaunchingWithOptions: can potentially be launched with options indicating that the app was called to handle a push notification, url, or something else. If your app can handle the given activity or url, you must return true.

.just do it