1:应用启动时调用的委托
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
2:切换至后台时调用的委托(即按home键)
- (void)applicationWillResignActive:(UIApplication *)application - (void)applicationDidEnterBackground:(UIApplication *)application
3:从后台恢复时调用的委托
- (void)applicationWillEnterForeground:(UIApplication *)application - (void)applicationDidBecomeActive:(UIApplication *)application
4:在后台关闭程序:
无
其实appDelegate中还有一个事件响应函数
- (void)applicationWillTerminate:(UIApplication *)application
注:(该函数在iOS4之前的系统不支持后台任务时,当按home键相当于退出程序,所以按home键会响应)
而到了iOS4之后,按home键等于enterbackground,如果双击home键以后在多任务栏里关闭程序,
那么也不会调用到applicationWillTerminate,因为在后台的程序默认是suspend,所以那样关闭,不会执行到该函数。
如果再切换到后台时候,把该程序标记为一个后台程序,那么系统还会分配cpu cycle给改程序,改程序还可以运行一段时间,
此时双击home键在多任务栏中关闭程序,就会调用到applicationWillTerminate了。
5:禁止程序运行时自动锁屏
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
6:设置App标记数量, 0表示隐藏
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;