ios 程序进入后台并返回 调用的方法
2014-11-23 10:09
239 查看
AppDelegate 中有好几个方法,分别是对应程序处于不同状态时进行调用,今天顺便进行了解下。还是使用最经常用的NSLog来进行打印。
[cpp] view
plaincopy
- (void)dealloc
{
[window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.rootViewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
[window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// 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.
NSLog(@"applicationWillResignActive");
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// 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.
NSLog(@"applicationDidEnterBackground");
}
- (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.
NSLog(@"applicationWillEnterForeground");
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// 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.
NSLog(@"applicationDidBecomeActive");
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
NSLog(@"applicationWillTerminate");
}
进入程序后先打印出 applicationDidBecomeActive 即先调用- (void)applicationDidBecomeActive:(UIApplication *)application
再让程序进入后台,先调用的是
- (void)applicationWillResignActive:(UIApplication *)application
再调用
- (void)applicationDidEnterBackground:(UIApplication *)application
同理,再点击程序图片再次进入程序先调用的是
- (void)applicationWillEnterForeground:(UIApplication *)application
再接着就调用
- (void)applicationDidBecomeActive:(UIApplication *)application
这样就对整个程序的运行状态初步了解了,你的APP在程序进入后台后要做什么返回后还得做什么就在相应的方法中码好你的代码就OK啦。
[cpp] view
plaincopy
- (void)dealloc
{
[window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.rootViewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
[window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// 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.
NSLog(@"applicationWillResignActive");
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// 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.
NSLog(@"applicationDidEnterBackground");
}
- (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.
NSLog(@"applicationWillEnterForeground");
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// 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.
NSLog(@"applicationDidBecomeActive");
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
NSLog(@"applicationWillTerminate");
}
进入程序后先打印出 applicationDidBecomeActive 即先调用- (void)applicationDidBecomeActive:(UIApplication *)application
再让程序进入后台,先调用的是
- (void)applicationWillResignActive:(UIApplication *)application
再调用
- (void)applicationDidEnterBackground:(UIApplication *)application
同理,再点击程序图片再次进入程序先调用的是
- (void)applicationWillEnterForeground:(UIApplication *)application
再接着就调用
- (void)applicationDidBecomeActive:(UIApplication *)application
这样就对整个程序的运行状态初步了解了,你的APP在程序进入后台后要做什么返回后还得做什么就在相应的方法中码好你的代码就OK啦。
相关文章推荐
- ios 程序进入后台并返回 调用的方法
- 转载:IOS 进入前台后台调用方法说明
- Swift - 程序进入后台,以及应用终止时调用的方法
- iOS---在controller里面自定义方法判断:home键进入后台,返回前台
- iOS程序进入后台后仍运行定时器NSTimer
- 利用广播调用后台服务方法并根据方法返回的内容更新UI
- 前台调用后台方法(返回字符串)
- 让程序在 iOS 4系统里直接退出不后台运行的方法
- IOS常用延迟调用,后台调用,主线程调用方法
- AJAX回调(调用后台方法返回数据)
- 客户端通过Ajax调用后台方法返回DataSet,Ilist,ilist,T,对象
- iOS程序进入后台后仍运行定时器NSTimer
- iOS程序之间相互调用启动方法
- iOS程序进入后台后仍运行定时器NSTimer
- iOS程序进入后台后仍运行定时器NSTimer
- jquery ajax调用后台方法返回json数据转自http://www.cnblogs.com/xiaoxi/archive/2011/03/31/2000803.html
- 在aspx页面里调用cs后台文件里的方法,返回结果到aspx页面
- iOS 4中禁止程序退出后保留在后台的方法
- ajax 同步调用 返回字符串 java例子(全)及 从后台返回中文乱码解决方法