- (void)applicationWillResignActive:(UIApplication *)application
{
//挂起,当你的程序被挂起后他不会在后台运行
//当应用程序将要入非活动状态执行,在此期间,应用程序不接收消息或事件,比如来电话了
//当有电话进来或者锁屏,这时你的应用程会挂起,在这时,UIApplicationDelegate委托会收到通知,调用 applicationWillResignAct// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - (void)applicationDidEnterBackground:(UIApplication *)application {iv//e 方法,你可以重写这个方法,做挂起前的工作,比如关闭网络,保存数据。
//程序进入后台
//当程序被推送到后台的时候调用。所以要设置后台继续运行,则在这个函数里面设置即可 // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - (void)applicationWillEnterForeground:(UIApplication *)application {
//程序进入前台
//当程序从后台将要重新回到前台时候调用 // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - (void)applicationDidBecomeActive:(UIApplication *)application {
//复原,应用程序在启动时,在调用了 applicationDidFinishLaunching 方法之后也会调用 applicationDidBecomeActi ve 方法,所以你要确保你的代码能够分清复原与启动,避免出现逻辑上的bug。 //当程序复原时,另一个名为 applicationDidBecomeActi// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.ve 委托方法会被调用,在此你可以通过之前挂起前保存的数据来恢复你的应用程序 }- (void)applicationWillTerminate:(UIApplication *)application{//终止
//当用户按下按钮,或者关机,程序都会被终止。当一个程序将要正常终止时会调用 applicationWillTerminate
方法。但是如果长主按钮强制退出,则不会调用该方法。这个方法该执行剩下的清理工作,比如所有的连接都能正常关闭,并在程序退出前执行任何其他的必要的工作: //当程序将要退出是被调用,通常是用来保存数据和一些退出前的清理工作。这个需要要设置UIApplicationExitsOnSuspend的键值 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. }
首次运行:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOp
tions:(NSDictionary *)launchOptions - (void)applicationDidBecomeActi
ve:(UIApplication *)application 首次关闭(home):
- (void)applicationWillResignAct
ive:(UIApplication *)application - (void)applicationDidEnterBackg
round:(UIApplication *)application 再次运行:
- (void)applicationWillEnterFore
ground:(UIApplication *)application - (void)applicationDidBecomeActi
ve:(UIApplication *)application 再次关闭:
- (void)applicationWillResignAct
ive:(UIApplication *)application - (void)applicationDidEnterBackg
round:(UIApplication *)application