iOS开发--AppDelegate文件下各方法的用法

类似于监听接口。 用个很简单的例子说:ios系统会控制每个程序的开始和结束。但是ios又不知道每个程序的开始需要运行成么代码,结束需要运行什么代码。这个时候,ios就制定了一个规则:如果你是我的代理程序,那么我在开始的时候就会运行你里面的– applicationDidFinishLaunching方法,我会在结束的时候运行你的– applicationWillTerminate方法,这是UIApplicationDeligate定义的接口。 



1. application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 


Tells the delegate when the application has launched and may have additional launch options to handle. 


在应用程序启动后,要执行的委托调用。 




2. applicationWillResignActive:(UIApplication *)application 


Tells the delegate that the application is about to become inactive.This method is called to let your application know that it is about to move from the active to inactive state.After calling this method, the application also posts a UIApplicationWillResignActiveNotification notification to give interested objects a chance to respond to the transition. 


在应用程序将要由活动状态切换到非活动状态时候,要执行的委托调用,如 按下 home 按钮,返回主屏幕,或全屏之间切换应用程序等。 




3. applicationDidEnterBackground:(UIApplication *)application 


Tells the delegate that the application is now in the background.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. 


在应用程序已进入后台程序时,要执行的委托调用。 




4. applicationWillEnterForeground:(UIApplication *)application 


Tells the delegate that the application is about to enter the foreground.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. 


在应用程序将要进入前台时(被激活),要执行的委托调用,刚好与 applicationWillResignActive 方法相对应。 




5. applicationDidBecomeActive:(UIApplication *)application 


Tells the delegate that the application has become active.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. 


在应用程序已被激活后,要执行的委托调用,刚好与  applicationDidEnterBackground 方法相对应。 



6. applicationWillTerminate:(UIApplication *)application 


Tells the delegate when the application is about to terminate.Called when the application is about to terminate. Save data if appropriate. 


在应用程序要完全推出的时候,要执行的委托调用。


AppDelegate文件下各方法的用法:(应用程序挂起、复原与终止):


首次运行:

- (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:(UIApplica tion *)application===> 程序进入后台 !


终止程序:

- (void)applicationWillTerminate:(UIApplication*)application===> 程序将终止 !

 在方法中利用:NSLog(@"%@", NSStringFromSelector(_cmd));输出正执行的方法;


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值