zoukankan      html  css  js  c++  java
  • APP的启动流程

    从 Main函数入口,来到appdelegate,创建Window,创建跟视图控制器并初始化视图load view、viewDidload、viewWillAppear、viewDidAppear;
    UIApplicationMain()⽅法主要有个功能:     
    1、创建应⽤程序的UIApplication对象;   
    2、创建引⽤程序代理实例; 
    3、建⽴事件循环(死循环),不断检测程序的运⾏状态,是否触摸,晃动。 
    APP执⾏过程: 
    启动程序/前台(活跃状态)/将要结束(活跃状态)/进⼊后台(不活跃状态)/将要
    进⼊前台/前台(活跃状态)。    
    这就是⼀个死循环,ios没有提供退出程序的机制,只有强制结束程序。 
    以下是各个状态下执⾏的对应⽅法。 
    //
    //  AppDelegate.m
    //  APP启动流程01
    //
    //  Created by cqy on 16/2/13.
    //  Copyright © 2016年 程清杨. All rights reserved.
    //

    #import "AppDelegate.h"

    @interface AppDelegate ()

    @end

    @implementation AppDelegate


    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        //程序启动之后执行,只有在第一次程序启动后才执行,以后不再执行;
          NSLog(@"程序已经启动...");
        // Override point for customization after application launch.
        return YES;
    }

    - (void)applicationWillResignActive:(UIApplication *)application {
        //程序将要被激活时(获得焦点)执行,程序激活用户才能操作;
           NSLog(@"程序将要失去焦点...");
        // 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 throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }
    //
    - (void)applicationDidEnterBackground:(UIApplication *)application {
        //程序进入后台后执行,注意进入后台时会先失去焦点再进入后台;
         NSLog(@"程序已经进入后台...");
        // 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 {
        //程序将要进入前台时执行
            NSLog(@"程序将要进入前台...");
        // 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.
    }

    - (void)applicationDidBecomeActive:(UIApplication *)application {
        //程序被激活(获得焦点)后执行,注意程序被激活时会先进入前台再 激活;
         NSLog(@"程序已经获得焦点...");
        // 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 {
        //程序在终止时执行,包括正常终止或异常终止,例如说一个应用程序在后太运行(例如音乐播放软件、社交软件等)占用太多内存这时会意外终止调用此方法;
         NSLog(@"程序将要终止...");
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }
    @end
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    IntelliJ IDEA 16创建Web项目
    Error running Tomcat8: Address localhost:1099 is already in use 错误解决
    Hibernate的三种状态
    Hibernate 脏检查和刷新缓存机制
    Windows服务器时间不同步问题
    解决Windows内存问题的两个小工具RamMap和VMMap
    实现多线程异步自动上传本地文件到 Amazon S3
    JS判断用户连续输入
    ASP.Net 重写IHttpModule 来拦截 HttpApplication 实现HTML资源压缩和空白过滤
    bootstrap的popover在trigger设置为hover时不隐藏popover
  • 原文地址:https://www.cnblogs.com/iQingYang/p/5193186.html
Copyright © 2011-2022 走看看