Lifecycle of an iOS Application

Ferdous Mahmud Akash

Ferdous Mahmud Akash

· 3 min read
iOS application lifecycle

Several states of an iOS application when it runs called the lifecycle of this application

As an iOS developer, you should be aware of the application life cycle

It helps us to understand the application's behavior.

The states are

  1. Not Running: the app is considered to be in a Not Running state when it is not yet launched or terminated by the system or user.
  2. Inactive: the app is in an inactive state when it is in the foreground but receiving events. In other words, we can say that it acts like a bridge state in which the app remains brief when it transitions to a different state.
  3. Active: it is a normal mode for the app when it is in the foreground state and receiving all the user events.
  4. Background: the app transitions into the background state when the user taps on the home screen while using the application, or it requires some extra execution time. When the app is about to be suspended, then also transitions into this state for a small amount of time. In this state, the app remains in the background and executes the code.
  5. Suspended: in this state, the app remains in the background and doesn't execute the code. The app is automatically moved to this state. In this state, the app remains in memory. However, foreground apps are always given priority over suspended apps and can be purged at any time without notice.

The main entry point of an iOS application is UIApplicationDelegate. It is a protocol that the application must need to implement to get notified of several user events. Such as...

  • App launch
  • App goes into the background
  • App comes into the foreground
  • Send push notification

The UIApplicationDelegate contains certain app lifecycle methods that are notified when the app starts running. The UIApplicationDelegate methods are given below.

  • application: didFinishLaunchingWithOptions:-> Bool: when the application is launched initially, this method is called. We can do any initial setup for the application in this method like firebase configuration, user navigation, etc. The storyboard is loaded at this point, but we can maintain the state restoration.
optional func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
) -> Bool
  • applicationWillEnterForeground: This method is called after didFinishLaunchingWithOptions. It is also called when the application comes from background to foreground.
optional func applicationWillEnterForeground(_ application: UIApplication)
  • applicationDidBecomeActive: this method is called after applicationWillEnterForeground. If we need to perform any particular task when the app comes into the foreground, like font update, etc., then we can place the code in this method.
optional func applicationWillEnterForeground(_ application: UIApplication)
  • applicationWillResignActive: this method is notified when the application is about to become inactive. For example, the user receives a phone call; the user presses the home button, etc.).
optional func applicationWillResignActive(_ application: UIApplication)
  • applicationDidEnterBackground: this method is notified when the application goes into a background state after becoming inactive.
optional func applicationDidEnterBackground(_ application: UIApplication)
  • applicationWillTerminate: this method is called when the application is about to be finally terminated from memory. If we need to perform any final cleanups, then we can place the code in this method.
optional func applicationWillTerminate(_ application: UIApplication)
Ferdous Mahmud Akash

About Ferdous Mahmud Akash

Hey there! I'm a self-taught iOS developer from Bangladesh.

I'm also passionate about sharing my knowledge and experience with other aspiring developers through my blog at ferdousmahmud.co

Thank you for visiting my website, and feel free to reach out if you have any questions or just want to say hello!

Copyright © 2021-2024 Ferdous Mahmud Akash. All rights reserved.
Made by Ferdous· Github
LinkTree