面对现实,超越自己
逆水行舟,不进则退
posts - 269,comments - 32,trackbacks - 0
第一步:
创建2个NSNotificationCenter监听
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification object:nil]; //监听是否触发home键挂起程序.
    
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification object:nil]; //监听是否重新进入程序程序.


第二步:
实现2个NSNotificationCenter所触发的事件方法
- (void)applicationWillResignActive:(NSNotification *)notification
{
    printf("按理说是触发home按下\n");
}
- (void)applicationDidBecomeActive:(NSNotification *)notification
{
    printf("按理说是重新进来后响应\n");
}


注: 在home键触发后,AppDelegate响应的方法为:

- (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. */ }

本文转自:http://blog.csdn.net/sqc3375177/article/details/9466687

其他相关信息:
  1. (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  2.  
  3.     // Override point for customization after application launch.  
  4.     NSLog(@"\n ===> 程序开始 !");   
  5.       
  6.     return YES;  
  7.  
  8.                               
  9. (void)applicationWillResignActive:(UIApplication *)application  
  10.  
  11.       
  12.     NSLog(@"\n ===> 程序暂行 !");   
  13.  
  14.   
  15. (void)applicationDidEnterBackground:(UIApplication *)application  
  16.  
  17.       
  18.      NSLog(@"\n ===> 程序进入后台 !");   
  19.  
  20.   
  21. (void)applicationWillEnterForeground:(UIApplication *)application  
  22.  
  23.       
  24.      NSLog(@"\n ===> 程序进入前台 !");   
  25.  
  26.   
  27. (void)applicationDidBecomeActive:(UIApplication *)application  
  28.  
  29.     NSLog(@"\n ===> 程序重新激活 !");   
  30.       
  31.  
  32.   
  33. (void)applicationWillTerminate:(UIApplication *)application  
  34.  
  35.     NSLog(@"\n ===> 程序意外暂行 !");   
  36.   
  37.     UIDevice *device [UIDevice currentDevice];  
  38.       
  39.  
 

首次运行

- (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


本文转自:http://friendlysong.blog.163.com/blog/static/3225243920128144251666/
posted on 2014-08-01 13:31 王海光 阅读(1806) 评论(0)  编辑 收藏 引用 所属分类: IOS

只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理