iOS开发之应用生命周期
2013-10-23 20:15
302 查看
在iphone程序中,main.m是入口文件,在main函数中又个入口函数:
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AndyAppDelegate class]));
}
参数说明:
argc和argv是ISO C标准的main函数的参数,直接传递给UIApplicationMain进行相关处理。
principalClassName是应用程序类的名字,该类必须继承自UIApplication类。
delegateClassName是应用程序类的代理类,该函数跟据delegateClassName创建一个delegate对象,并将UIApplication对象中的delegate属性设置为delegate对象
UIApplicationMain的作用:
1. 创建UIApplication对象
2.在类-info.plist中寻找由NSMainNib所定义的主窗口界面,将其装入内存并实例化其中的对象,如果没有这一项,则不会实例化。
每一个程序在运行期必须有且仅有一个UIApplication(或则其子类)的一个实例。创建UIApplication的单例实例。这样可以通过调用[UIApplication sharedApplication]来得到这个单例实例的指针。
UIApplication的一个主要工作是处理用户事件,它会起一个队列,把所有用户事件都放入队列,逐个处理,在处理的时候,它会发送当前事件 到一个合适的处理事件的目标控件。此外,UIApplication实例还维护一个在本应用中打开的window列表(UIWindow实例),这样它就 可以接触应用中的任何一个UIView对象。UIApplication实例会被赋予一个代理对象,以处理应用程序的生命周期事件(比如程序启动和关闭)、系统事件(比如来电、记事项警告)等等
以下是官方解释:
UIApplicationMain
This function is called in the main entry point to create the application object and the application delegate and set up the event cycle.
创建UIApplication单例,设置该单例的delegate,设置一个时间循环周期。
int UIApplicationMain (
int argc,
char *argv[],
NSString *principalClassName,
NSString *delegateClassName
);
Parameters
argc
The count of arguments in argv; this usually is the corresponding parameter to main.
argv
A variable list of arguments; this usually is the corresponding parameter to main.
principalClassName
The name of the UIApplication class or subclass. If you specify nil, UIApplication is assumed.
delegateClassName
The name of the class from which the application delegate is instantiated. If principalClassName designates a subclass of UIApplication, you may designate the subclass as
the delegate; the subclass instance receives the application-delegate messages. Specify nil if you load the delegate object from your application’s main nib file.
Return Value
Even though an integer return type is specified, this function never returns. When users exits an iOS application by pressing the Home button, the application moves to
the background.
更多内容可以参考:
点击打开链接
(出处: Android开发论坛 - 安卓开发论坛 - Android开发 - 安卓论坛 - 移动互联网门户)
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AndyAppDelegate class]));
}
参数说明:
argc和argv是ISO C标准的main函数的参数,直接传递给UIApplicationMain进行相关处理。
principalClassName是应用程序类的名字,该类必须继承自UIApplication类。
delegateClassName是应用程序类的代理类,该函数跟据delegateClassName创建一个delegate对象,并将UIApplication对象中的delegate属性设置为delegate对象
UIApplicationMain的作用:
1. 创建UIApplication对象
2.在类-info.plist中寻找由NSMainNib所定义的主窗口界面,将其装入内存并实例化其中的对象,如果没有这一项,则不会实例化。
每一个程序在运行期必须有且仅有一个UIApplication(或则其子类)的一个实例。创建UIApplication的单例实例。这样可以通过调用[UIApplication sharedApplication]来得到这个单例实例的指针。
UIApplication的一个主要工作是处理用户事件,它会起一个队列,把所有用户事件都放入队列,逐个处理,在处理的时候,它会发送当前事件 到一个合适的处理事件的目标控件。此外,UIApplication实例还维护一个在本应用中打开的window列表(UIWindow实例),这样它就 可以接触应用中的任何一个UIView对象。UIApplication实例会被赋予一个代理对象,以处理应用程序的生命周期事件(比如程序启动和关闭)、系统事件(比如来电、记事项警告)等等
以下是官方解释:
UIApplicationMain
This function is called in the main entry point to create the application object and the application delegate and set up the event cycle.
创建UIApplication单例,设置该单例的delegate,设置一个时间循环周期。
int UIApplicationMain (
int argc,
char *argv[],
NSString *principalClassName,
NSString *delegateClassName
);
Parameters
argc
The count of arguments in argv; this usually is the corresponding parameter to main.
argv
A variable list of arguments; this usually is the corresponding parameter to main.
principalClassName
The name of the UIApplication class or subclass. If you specify nil, UIApplication is assumed.
delegateClassName
The name of the class from which the application delegate is instantiated. If principalClassName designates a subclass of UIApplication, you may designate the subclass as
the delegate; the subclass instance receives the application-delegate messages. Specify nil if you load the delegate object from your application’s main nib file.
Return Value
Even though an integer return type is specified, this function never returns. When users exits an iOS application by pressing the Home button, the application moves to
the background.
更多内容可以参考:
点击打开链接
(出处: Android开发论坛 - 安卓开发论坛 - Android开发 - 安卓论坛 - 移动互联网门户)
相关文章推荐
- 在开发iOS程序时对日期处理的总结
- iOS开发——keychain的使用
- iOS Graphics Technologies iOS 图形技术
- iOS开发异常错误总结
- 学习Objective-C:入门手册
- ios开发对配置文件plist的操作
- iphone5和4的屏幕兼容问题
- 后天工作室简介
- iOS开发笔记
- 广州知名游戏公司招贤纳士啦~~~
- 谈谈怎么最快学好iOS开发(个人看法)
- ios长按事件
- iOS 获取应用版本号
- iOS中定时器NSTimer的使用
- IOS开发随感
- 解决IOS开发使用Lumberjack库时出现的Use of undeclared identifier 'ddLogLevel'问题
- 《Objective-C基础教程》学习笔记第二章
- 《Objective-C基础教程》学习笔记第三-六章
- 《Objective-C基础教程》学习笔记第八章
- 《Objective-C基础教程》学习笔记第九-十章