- - (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应用程序的各种生命周期方法,包括启动、进入前台、后台以及终止等不同阶段的行为。通过理解这些方法的作用时机,开发者可以更好地管理应用资源,确保应用程序在各种状态转换时表现良好。
2051

被折叠的 条评论
为什么被折叠?



