美文网首页
AppDeleagte的生命周期

AppDeleagte的生命周期

作者: 小苗晓雪 | 来源:发表于2017-04-15 23:23 被阅读51次

    一个App从打开到关闭 , 这中间都经历了哪些方法 ?! 未激活(applicationWillResignActive), 激活(applicationDidBecomeActive), 即将进入前台(applicationWillEnterForeground) , 已经进入后台(applicationDidEnterBackground) , 将要启动(willFinishLaunchingWithOptions) , 已经启动(applicationDidFinishLaunching) , 终止(applicationWillTerminate)
    等等....很多的方法....都在
    @protocol UIApplicationDelegate<NSObject>这个代理方法里!

    AppDelegate.h文件

    
    #import "AppDelegate.h"
    //#import "BaseTabBarController.h"
    #import "ADViewController.h"
    
    @interface AppDelegate ()
    
    @end
    
    @implementation AppDelegate
    
    //每次程序启动的时候就进入广告界面 , 窗口的根控制器设置为广告控制器 ;
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // 1.创建窗口:
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
        // 2.设置窗口根控制器:
        //定制BaseTabBarController:
    //    self.window.rootViewController = [[BaseTabBarController alloc] init] ;
        //定制ADViewController:一进来就是广告界面为窗口的根控制器:
        self.window.rootViewController = [[ADViewController alloc] init] ;
        // 3.显示窗口:让self.window成为UIApplication的主窗口并且显示:
        [self.window makeKeyAndVisible] ;
        
        return YES;
    }
    
    - (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        NSLog(@"告诉AppDelegate程序代理 , 进程启动但还没有进入状态保存") ;
        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 invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }
    
    
    - (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.
    }
    
    
    - (void)applicationWillEnterForeground:(UIApplication *)application {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }
    
    
    - (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.
    }
    
    
    - (void)applicationWillTerminate:(UIApplication *)application {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }
    
    
    @end
    
    

    愿编程让这个世界更美好

    相关文章

      网友评论

          本文标题:AppDeleagte的生命周期

          本文链接:https://www.haomeiwen.com/subject/lsmoattx.html