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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

你可能感兴趣的:(APP的启动流程)