一、挂起
当有电话进来或者锁屏,这时你的应用程会挂起,在这时,UIApplicationDelegate委托会收到通知,调用 applicationWillResignActive 方法,你可以重写这个方法,做挂起前的工作,比如关闭网络,保存数据。
C代码 收藏代码
- (void)applicationWillResignActive:(UIApplication*)application{
}
当你的程序被挂起后他不会在后台运行。
二、复原
当程序复原时,另一个名为 applicationDidBecomeActive 委托方法会被调用,在此你可以通过之前挂起前保存的数据来恢复你的应用程序:
C代码 收藏代码
- (void)applicationDidBecomeActive:(UIApplication*)application{
}
注意:应用程序在启动时,在调用了 applicationDidFinishLaunching 方法之后也会调用 applicationDidBecomeActive 方法,所以你要确保你的代码能够分清复原与启动,避免出现逻辑上的bug。
三、终止
当用户按下按钮,或者关机,程序都会被终止。当一个程序将要正常终止时会调用 applicationWillTerminate 方法。但是如果长主按钮强制退出,则不会调用该方法。这个方法该执行剩下的清理工作,比如所有的连接都能正常关闭,并在程序退出前执行任何其他的必要的工作:
C代码 收藏代码
- (void)applicationWillTerminate:(UIApplication*)application{
}
来源: http://blog.csdn.NET/iukey/article/details/7311115
Java代码 程序开始 !"); return YES; } - (void)applicationWillResignActive:(UIApplication *)application { NSLog(@"\n ===> 程序暂行 !"); } - (void)applicationDidEnterBackground:(UIApplication *)application { NSLog(@"\n ===> 程序进入后台 !"); } - (void)applicationWillEnterForeground:(UIApplication *)application { NSLog(@"\n ===> 程序进入前台 !"); } - (void)applicationDidBecomeActive:(UIApplication *)application { NSLog(@"\n ===> 程序重新激活 !"); } - (void)applicationWillTerminate:(UIApplication *)application { NSLog(@"\n ===> 程序意外暂行 !"); UIDevice *device = [UIDevice currentDevice]; }" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> 收藏代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
NSLog(@"\n ===> 程序开始 !");
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
NSLog(@"\n ===> 程序暂行 !");
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSLog(@"\n ===> 程序进入后台 !");
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSLog(@"\n ===> 程序进入前台 !");
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
NSLog(@"\n ===> 程序重新激活 !");
}
- (void)applicationWillTerminate:(UIApplication *)application
{
NSLog(@"\n ===> 程序意外暂行 !");
UIDevice *device = [UIDevice currentDevice];
}
首次运行:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- (void)applicationDidBecomeActive:(UIApplication *)application
首次关闭(home):
- (void)applicationWillResignActive:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application
再次运行:
- (void)applicationWillEnterForeground:(UIApplication *)application
- (void)applicationDidBecomeActive:(UIApplication *)application
再次关闭:
- (void)applicationWillResignActive:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application