您的位置:首页 > 移动开发

UIApplicationMain

2013-10-27 21:30 411 查看
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil,
NSStringFromClass([AppDelegate class]));
}
}

1. UIApplicationMain creates your app’s first instance — the shared application instance, which is to be subsequently accessible in code by calling [UIApplication sharedApplication].

The third argument in the call to UIApplicationMain specifies, as a string, what class the shared application instance should be an instance of. If nil, which will usually be the case, the default class is UIApplication.

2.
UIApplicationMain creates your app’s second instance — the application instance’s
delegate.
The fourth argument in the call to UIApplicationMain specifies, as a string, what class the app delegate instance should be. In our
main.m, that specification is:
NSStringFromClass([AppDelegate class])

3.
If the Info.plist file specifies a main storyboard file, UIApplicationMain loads it and looks inside it to find the view controller that is designated as this storyboard’s
initial view controller; it instantiates this view controller, thus creating your app’s
third instance.

4.
If there was a main storyboard file, UIApplicationMain now creates your app’s
window by instantiating the UIWindow class — this is your app’s fourth instance.

It assigns this window instance as the app delegate’s window property;
it also assigns the initial view controller instance as the window instance’s
root view controller (rootViewController property).

5.
UIApplicationMain now turns to the app delegate instance and starts calling some of its code — in particular, it calls application:didFinishLaunchingWithOptions:. This is an opportunity for your own code to run!

but you don’t want anything time-consuming to happen here, because your app’s interface still hasn’t appeared.
(
Starting in iOS 6, the sequence of calls to the app delegate’s code actually begins with application:willFinishLaunchingWithOptions: if it exists.
)

6.
If there was a main storyboard, UIApplicationMain now causes your app’s interface to appear. It does this by calling the UIWindow instance method
makeKeyAndVisible.

7.
The window is now about to appear. This, in turn, causes the window to turn to its root view controller and tell it to obtain its main view, which will occupy and appear in the window. If this view controller gets its view
from a .storyboard or .xib file, the corresponding nib is now loaded; its objects are instantiated and initialized, and they become the objects of the initial interface.

The app is now launched and visible to the user. It has an initial set of instances — at a minimum, the shared application instance, the window, the initial view controller, and the initial view controller’s view and whatever interface objects
it contains. Some of your code (the app delegate’s application:didFinishLaunchingWithOptions:) has run, and we are now off to the races: UIApplicationMain is still running (like Charlie on the M.T.A., UIApplicationMain never returns), and is just sitting there,
watching for the user to do something, maintaining the event loop, which will respond to user actions as they occur.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: