ios程序不同状态下,调用的代理方法

  1. - (void)dealloc  
  2. {  
  3.     [window release];  
  4.     [super dealloc];  
  5. }  
  6.   
  7. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  8. {  
  9.     window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
  10.     window.rootViewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];  
  11.     [window makeKeyAndVisible];  
  12.     return YES;  
  13. }  
  14.   
  15. - (void)applicationWillResignActive:(UIApplication *)application  
  16. {  
  17.     // 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.  
  18.     // 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.  
  19.     NSLog(@"applicationWillResignActive");  
  20. }  
  21.   
  22. - (void)applicationDidEnterBackground:(UIApplication *)application  
  23. {  
  24.     // 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.   
  25.     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.  
  26.     NSLog(@"applicationDidEnterBackground");  
  27. }  
  28.   
  29. - (void)applicationWillEnterForeground:(UIApplication *)application  
  30. {  
  31.     // 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.  
  32.     NSLog(@"applicationWillEnterForeground");  
  33. }  
  34.   
  35. - (void)applicationDidBecomeActive:(UIApplication *)application  
  36. {  
  37.     // 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.  
  38.     NSLog(@"applicationDidBecomeActive");  
  39. }  
  40.   
  41. - (void)applicationWillTerminate:(UIApplication *)application  
  42. {  
  43.     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.  
  44.     NSLog(@"applicationWillTerminate");  

  1. }  

进入程序后先打印出 applicationDidBecomeActive 即先调用- (void)applicationDidBecomeActive:(UIApplication *)application

再让程序进入后台,先调用的是

- (void)applicationWillResignActive:(UIApplication *)application

再调用

- (void)applicationDidEnterBackground:(UIApplication *)application

同理,再点击程序图片再次进入程序先调用的是

- (void)applicationWillEnterForeground:(UIApplication *)application

再接着就调用

- (void)applicationDidBecomeActive:(UIApplication *)application

这样就对整个程序的运行状态初步了解了,你的APP在程序进入后台后要做什么返回后还得做什么就在相应的方法中码好你的代码就OK啦。


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值