Site icon CodeWithSwift

Application Life Cycle

The app transitions through the following states in its life cycle:

  1. Not Running:
    • The app is not launched and not running.
  2. Inactive:
    • The app is running in the foreground but not receiving user input.
    • Occurs during temporary interruptions (e.g., an incoming phone call or notification).
  3. Active:
    • The app is running in the foreground and actively receiving user input.
  4. Background:
    • The app is no longer visible but still executing code.
    • Used for tasks like saving data, fetching content, or playing audio.
  5. Suspended:
    • The app is in memory but not executing any code.
    • It can be terminated by the system if memory is needed.

The application life cycle is managed by the AppDelegate and SceneDelegate.

1.application(_:didFinishLaunchingWithOptions:)

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Initialization code
    print("App did finish launching")
    return true
}

2.applicationDidBecomeActive(_:)

func applicationDidBecomeActive(_ application: UIApplication) {
    print("App became active")
}

3.applicationWillResignActive(_:)

func applicationWillResignActive(_ application: UIApplication) {
    print("App will resign active")
}

4.applicationDidEnterBackground(_:)

Called when the app enters the background.

func applicationDidEnterBackground(_ application: UIApplication) {
    print("App entered background")
}

5.applicationWillEnterForeground(_:)

Called as the app transitions from background to foreground.

func applicationWillEnterForeground(_ application: UIApplication) {
    print("App will enter foreground")
}

6.applicationWillTerminate(_:)

Called when the app is about to terminate.

func applicationWillTerminate(_ application: UIApplication) {
    print("App will terminate")
}
Exit mobile version