Thursday, November 21, 2013

iOS App life cycle

Today will see the iOS App life cycle, mainly on
1) The App Launch Cycle
2) The View Controller Life Cycle

1) The App Launch Cycle

Lets see as soon as you tap on any application icon to open any iOS app in your device springboard what will happen,

- As part of the launch cycle, the iOS system creates a process and main thread for your app and calls your app’s main function on that main thread.

- The default main function that comes with your Xcode project promptly hands control over to the UIKit framework, it will initialize your app and prepares it to run.

Below flowchart (diagram from Apple’s developer docs: https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/Art/app_launch_fg_2x.png) will show the sequence of events that occurs when an app is launched into the foreground


The main function’s main job is to hand control to the UIKit framework.

2) The View Controller Life Cycle

Now lets see once your app is launched then say your first screen (Root/Home View Controller), how it will load in to the screen in other words the view controller life cycle hierarchy,
If you are creating your UI or View programmatically then the first method which gets called is loadView, followed by viewDidLoad -> viewWillAppear -> viewDidAppear  and while moving to the next screen or view Controller the hierarchy of methods are like viewWillDisappear -> viewDidDisappear -> viewDidUnload  

Note: In iOS 6 and later, viewDidUnload method is deprecated since views are no longer purged under low-memory conditions.

viewDidLoadCalled only once during the initial load of interface builder(.xib) file. Initial set up of view controller can be taken care here.

viewWillAppear – This method gets called just before your view appears or renders on screen every time when you navigate or switch between different views. Suppose if you want to update your view different while switching back and forth based on some requirement for that kind of dynamic changes to the views can be done here.

viewDidAppear – Once your view loads completely on screen this method gets called and here you can handle further UI or functionalities w.r.t your view controller like database call or whatever you want to do after loading your view.

viewWillDisappear - This method is called before the view is actually removed and before any animations are configured. Notifies the view controller that its view is about to be removed from a view hierarchy.

viewDidDisappear - This method notifies the view controller that its view was removed from a view hierarchy, here you can perform additional tasks associated with dismissing or hiding the view.

viewDidUnload - Called when the controller’s view is released from memory. In iOS 6 and later, clearing references to views and other objects in your view controller is unnecessary. In iOS 6 and later, viewDidUnload method is deprecated.


 Hope this post is helpful,any comments or suggestions is acceptable.



15 comments:

  1. Awsome Explanation brother..............

    ReplyDelete
  2. Replies
    1. @ravindra Firstly many thanks for liking and following my blog, yep sure I will come up with many more tutorials soon, since I was busy with my daily schedule I was unable to post frequently.
      Thanks :)

      Delete
  3. Nice blogs.
    Videocon and stay in touch with your Contacts, Friends, and Loved ones.
    Seamless Roaming across India. National Roaming is Pre-Activated on Videocon Prepaid Connection with Zero Monthly Rentals.
    Tariff while Roaming anywhere in India.

    ReplyDelete
  4. It’s really amazing that we can record what our visitors do on our site. Thanks for sharing this awesome guide. I’m happy that I came across with your site this article is on point,thanks again and have a great day. Keep update more information..


    iOS Training in Chennai

    ReplyDelete
  5. I am expecting more interesting topics from you. And this was nice content and definitely it will be useful for many people.

    Mobile App Development Company in Chennai
    Android app Development Company in Chennai
    ios app development Company in Chennai

    ReplyDelete
  6. It's interesting that many of the bloggers your tips helped to clarify a few things for me as well as giving.. very specific nice content. And tell people specific ways to live their lives.Sometimes you just have to yell at people and give them a good shake to get your point across.
    Mobile App Development Company
    Android app Development Company
    ios app development Company
    Mobile App Development Companies

    ReplyDelete