OBJECTIVES:

This blog is all about life-cycle about iOS Application. iOS Application means iPhone and iPad both application runs on user’s iOS device. Every iOS developer should aware about this life-cycle.

iOS developer at beginner level should know about life cycle of the iOS application. This helps with develop proper application. It’s also help with manage all different states of application during this Life Cycle. Once you do know about iOS Life Cycle as a developer your life gets must easier to handling things in application.

Normally iOS Life-Cycle shown in below Diagram:-

iOS Life-Cycle

As per above drawn diagram: it’s basic structure of iOS Application flow diagram OR Life Cycle whatever you want to call. It basically starts with didFinishLaunching method and ends with applicationWillTerminate method.

This all cycle stage you can found in AppDelegate file.

  • If working on Objective-C project than it’s AppDelegate.h & AppDelegate.m file.
  • If working on Swift project than it’s AppDelegate.swift file.

Let’s explore more about this Life-Cycle stages; which are:

didFinishLaunchingWithOptions:

This method runs when application first time open or launch. As per its name; it's clearly indicate that this method calls after Launch finish.

Check this method in Xcode:

OBJECTIVE-C:


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    return YES;
}

SWIFT:


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }


applicationWillEnterForeground:

This method runs when application enter in foreground means application comes to screen on user’s device. It’s name confront clea its meaning. In this execution of function there is another function with name handleOpenURL method which also handle urls open with application and returns back callback url to the application.

Check this method in Xcode:

OBJECTIVE-C:


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

SWIFT:


func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

applicationDidBecomeActive & applicationWillResignActive:

This methods and following methods are called in one after one manner means async type of calling. This methods are only 1 word difference Did & Will which makes their functionality different in application life cycle. DidBecomeActive called first means ready stage of Become Active and other one WillResignActive called when ready to resign active state of application.

Check this method in Xcode:

OBJECTIVE-C:


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


SWIFT:


func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

applicationDidEnterBackground:

As per name; Now you should identify the called time of this method in application life cycle. Yeah, Correct. This method called when application goes in background state. In iOS device when user click HOME button once means in Background mode.

Check this method in Xcode:

OBJECTIVE-C:


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

SWIFT:


func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

applicationWillTerminate:

This is last stage of lifecycle of application where user quite or close application from active state or background state. Terminate itself mean Quit of the application and last stage of Life Cycle.

Check this method in Xcode:

OBJECTIVE-C:


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

SWIFT:


func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }

So, that’s the flow of iOS Application Life Cycle. Each & every developer should understand it very properly and clear. So, let me know if you have any doubts or query regarding iOS life cycle.

Contact us; If you have any query regarding iOS Application / Apple Watch Application / iMessage Extension / Today’s Extension OR you have your own application idea let us know. We have expert iOS team for your help.