Eric Brotto
Eric Brotto

Reputation: 54251

What happens when main is called in an iPhone or iPad app?

I am currently trying to debug a problem with an iPhone app. When I run it in Xcode main is called, but not - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions. This leads me to an essential question which should help me resolve this problem, but also understand more the startup sequence of an iPhone/ iPad application. So, can anyone explain in a succinct manner what happens when main is called in an iPhone or iPad app?

Thanks!

Upvotes: 2

Views: 216

Answers (3)

Owen Hartnett
Owen Hartnett

Reputation: 5935

Note also that if you create a new project in Xcode with one of the templates, Xcode will build a very nice main method that will definitely call didFinishLaunchWithOptions for you, which you can analyze and follow Xcode's lead.

Upvotes: 0

Eric Brotto
Eric Brotto

Reputation: 54251

I just found this which is pretty interesting.

Upvotes: 1

Mann
Mann

Reputation: 2118

When main is called,

UIKIT_EXTERN int UIApplicationMain(int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName);

is called.

Here is what Apple has to say for this method.

If nil is specified for principalClassName, the value for NSPrincipalClass from the Info.plist is used. If there is no NSPrincipalClass key specified, the UIApplication class is used. The delegate class will be instantiated using init.

You can check these entries in the main.h or the info.plist.

Upvotes: 1

Related Questions