博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UIApplicationDelegateDemo--应用程序前台、后台分析
阅读量:6847 次
发布时间:2019-06-26

本文共 3050 字,大约阅读时间需要 10 分钟。

  建立UIApplicationDelegateDemo主要用来明确应用程序进入前台、按home键进入后台以及在此唤醒进入前台函数的调用顺序。

1 //  2 //  AppDelegate.h  3 //  UIApplicationDelegateDemo  4 //  5 //  Created by Fox on 12-3-14.  6 //  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.  7 //  8  9 #import 
10 11 @class ViewController; 12 13 @interface AppDelegate : UIResponder
{
14 15 } 16 17 @property (strong, nonatomic) UIWindow *window; 18 @property (strong, nonatomic) ViewController *viewController; 19 20 @end
1 //  2 //  AppDelegate.m  3 //  UIApplicationDelegateDemo  4 //  5 //  Created by Fox on 12-3-14.  6 //  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.  7 //  8  9 #import "AppDelegate.h" 10 11 #import "ViewController.h" 12 13 @implementation AppDelegate 14 15 @synthesize window = _window; 16 @synthesize viewController = _viewController; 17 18 - (void)dealloc 19 {
20 [_window release]; 21 [_viewController release]; 22 [super dealloc]; 23 } 24 /* 25 *当程序完成载入,并且可能有额外的启动选项时被调用,用于程序的初始化 26 */ 27 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 28 {
29 NSLog(@"Fox:didFinishLaunchingWithOptions"); 30 self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 31 self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 32 self.window.rootViewController = self.viewController; 33 [self.window makeKeyAndVisible]; 34 return YES; 35 } 36 /* 37 *应用程序初始化完成后,程序转为激活状态时被调用 38 */ 39 - (void)applicationDidBecomeActive:(UIApplication *)application 40 {
41 NSLog(@"Fox:applicationDidBecomeActive"); 42 /* 43 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. 44 */ 45 } 46 47 48 /* 49 *应用程序转为后台(非激活)状态时被调用,即按home键后先调用该方法 50 */ 51 - (void)applicationWillResignActive:(UIApplication *)application 52 {
53 NSLog(@"Fox:applicationWillResignActive"); 54 } 55 56 /* 57 *程序转到后台后,调用此方法,若想在后台运行程序,在此处添加. 58 *应用此方法来释放资源,保存数据,使计时器停止,存储应用程序状态和信息 59 */ 60 - (void)applicationDidEnterBackground:(UIApplication *)application 61 {
62 NSLog(@"Fox:applicationDidEnterBackground"); 63 } 64 65 66 /* 67 *应用程序将要从后台进入前台时调用带方法 68 */ 69 - (void)applicationWillEnterForeground:(UIApplication *)application 70 {
71 NSLog(@"Fox:applicationWillEnterForeground"); 72 /* 73 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. 74 */ 75 } 76 77 78 /* 79 *应用程序将要终止时调用 80 */ 81 - (void)applicationWillTerminate:(UIApplication *)application 82 {
83 NSLog(@"Fox:applicationWillTerminate"); 84 /* 85 Called when the application is about to terminate. 86 Save data if appropriate. 87 See also applicationDidEnterBackground:. 88 */ 89 } 90 91 @end

程序运行后,调用的函数如下:

点击home键后:

在此点击程序,程序返回主界面:

转载地址:http://ozoul.baihongyu.com/

你可能感兴趣的文章
几种不同类型的消息队列
查看>>
ssh2项目整合 struts2.1+hibernate3.3+spring3 基于hibernate注解和struts2注解
查看>>
(转)RabbitMQ学习之Headers交换类型(java)
查看>>
2017.7.15清北夏令营精英班Day1解题报告
查看>>
UML之状态图
查看>>
python 的日志logging模块
查看>>
Swift开发教程--使用Storyboard进行界面跳转
查看>>
nmon使用
查看>>
svn删除文件或文件夹后提交失败及解决
查看>>
深入理解this和call、bind、apply对this的影响及用法
查看>>
nginx中文文档
查看>>
secureCRT连接不上linux的当中一个最大的原因
查看>>
Linux-kill命令和killall命令(11)
查看>>
android webview
查看>>
三刺激值
查看>>
SimpleRpc-系统边界以及整体架构
查看>>
istio入门(02)istio的架构和概念
查看>>
Docker container常用命令
查看>>
masscan
查看>>
Ubuntu 16.04下快速在当前目录打开终端的快捷键设置
查看>>