标签:
iOS程序的启动过程
程序启动的完整过程大致步骤如下:
1.main函数
2.UIApplicationMain
* 创建UIApplication对象
* 创建UIApplication的delegate对象
3.delegate对象开始处理(监听)系统事件(没有storyboard)
* 程序启动完毕的时候, 就会调用代理的application:didFinishLaunchingWithOptions:方法
* 在application:didFinishLaunchingWithOptions:中创建UIWindow
* 创建和设置UIWindow的rootViewController
* 显示窗口
3.根据Info.plist获得最主要storyboard的文件名,加载最主要的storyboard(有storyboard)(可与上步骤同时进行)
* 创建UIWindow
* 创建和设置UIWindow的rootViewController
* 显示试图
在iOS中打开程序后会按照如下图所示步骤启动
UIApplicationMain函数
//argc、argv:直接传递给UIApplicationMain进行相关处理即可 //principalClassName:指定应用程序类名(app的象征),该类必须是UIApplication(或子类)。如果为nil,则用UIApplication类作为默认值 //delegateClassName:指定应用程序的代理类,该类必须遵守UIApplicationDelegate协议 int UIApplicationMain(int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName);
@property(nonatomic) NSInteger applicationIconBadgeNumber;
@property(nonatomic,getter=isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible;
UIApplication的openURL方法
- (BOOL)openURL:(NSURL*)url;
1.打电话
UIApplication *app = [UIApplication sharedApplication]; [app openURL:[NSURL URLWithString:@"tel://10086"]];
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString:@"sms://10086"]];
3.发邮件
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString:@"mailto://12345@qq.com"]];
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString:@"http://www.baidu.com"]];
UIWindow
- (void)addSubview:(UIView *)view;
//直接将view添加到UIWindow中,但并不会理会view对应的UIViewController
@property(nonatomic,retain) UIViewController *rootViewController; //自动将rootViewController的view添加到UIWindow中,负责管理rootViewController的生命周期
- (void)makeKeyWindow;
//让当前UIWindow变成keyWindow(主窗口)
- (void)makeKeyAndVisible; //让当前UIWindow变成keyWindow,并显示出来
3.UIWindow的获取方法
[UIApplication sharedApplication].windows
[UIApplication sharedApplication].keyWindow
view.window
四大对象(UIApplication,AppDelegate,UIWindow,UIViewController)关系图
Info.plist常见的设置
标签:
原文地址:http://www.cnblogs.com/JackieHoo/p/5046935.html