Question

Which method and function is called first when any iOS application start ?

Was it helpful?

Solution

I suppose its

int main(int argc, char *argv[])

in main.m file

But for practical purposes I think you usually need to implement some of the UIApplicationDelegate's methods, depending on situation:

application:didFinishLaunchingWithOptions:
applicationDidBecomeActive:
applicationWillEnterForeground:

OTHER TIPS

If A View starts up, then it's:

- (void)viewDidLoad {}

If an app starts up it's:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:

or

- (void)applicationWillEnterForeground:(UIApplication *)application {

I think you'l be better of using the ViewDidLoad Method.

I hope i helped!

actually:

- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions{}

comes before:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{}

when application launches, first of all application:didFinishLaunchingWithOptions: method is called..

After when view is launched

at that time viewDidLoad is executed;

Have look at image According to apple doc

  • (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions{}

gets called before

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{}

First function called during app launch

int main(int argc, char *argv[])

First method called during app launch

application(_:willFinishLaunchingWithOptions:)

UIKit handle most of app launch tasks.

1) The app is launched, either explicitly by the user or implicitly by the system.

2) The Xcode-provided main function calls UIKit's UIApplicationMain() function.

3) The UIApplicationMain() function creates the UIApplication object and your app delegate.

4) UIKit loads your app's default interface from the main storyboard or nib file.

5) UIKit calls your app delegate's application(_:willFinishLaunchingWithOptions:) method.

6) UIKit performs state restoration, which calls additional methods of your app delegate and view controllers.

7) UIKit calls your app delegate's application(_:didFinishLaunchingWithOptions:) method.

The app launch and initialization sequence

Reference - https://developer.apple.com/documentation/uikit/app_and_environment/responding_to_the_launch_of_your_app/about_the_app_launch_sequence

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top