APP的启动流程

摘要:
在Main函数条目中,转到appdelegate,创建一个窗口,创建以下视图控制器,并初始化视图loadview、viewDidload、viewWillAppear和viewDidAppel;UIApplicationMain()方法有三个主要功能:1。创建应用程序的UIApplication对象;2.创建应用代理实例;3.创建一个事件循环(死循环),以持续检测程序的运行状态,无论它是否触摸或抖动。这是一个死循环。ios不提供退出程序的机制,而只是强制程序结束。
从 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的启动流程》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇浅谈Slick(4)- Slick301:我的Slick开发项目设置Spring框架系列(六)--事务Transaction下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

iOS 图片本地存储、本地获取、本地删除

在iOS开发中、经常用到图片的本地化。iOS 图片本地存储、本地获取、本地删除,可以通过以下类方法实现。 //将图片保存到本地 + (void)SaveImageToLocal:(UIImage*)image Keys:(NSString*)key { //首先,需要获取沙盒路径 NSString*picPath=[NSStringstringWithF...

iOS ---不一样的NSLog打印(精准打印)

  在iOS开发过程中,调试是很重要的过程,而除了各种断点调试(普通断点、条件断点、全局断点)之外,似乎NSLog是我们调试最常用的方法,当然,也是最简单朴素的寻debug方法。   在项目中,我们常使用的NSLog的语句无外乎以下一种:    NSLog(@"打印字符串:%@",name); NSLog(@"打印整形:%i",number);//或...

NSLog打印信息的从新设置

前提:在XCode做开发调试时往往需要打印一些调试信息做debug用,大家知道当打印信息的地方多了之后在模拟器上跑可能不会有什么问题,因为模拟器用的是电脑的硬件但是当应用跑在设备上时这些输出语句会在很大程度上影响应用的性能,针对这种问题可以写一些宏来控制这些调试信息的输出。 在release版本禁止输出NSLog内容 因为NSLog的输出还是比较消耗系统资...

iOS 测试 | iOS 自动化性能采集

​今天小编跟大家分享一篇来自学院内部学员的技术分享,本文主要介绍了作者在进行 iOS 自动化性能采集的一些经验,希望对大家在进行 iOS 自动化测试时有一些启发。 不要为小事遮住视线,我们还有更大的世界 前言 对于iOS总体生态是比较封闭的,相比Android没有像adb这种可以查看内存、cpu的命令.在日常做性能测试,需要借助xcode中instrum...

IOS ——OC—— NSDictionary的使用总结

键与值一一对应,键不能重复; 值可以重复; 1.NSDictionary的创建:(字典的内容是无序的,不能进行排序)  NSDictionary *dic = [NSDictionary dictionary];//创建一个空字典                 NSDictionary *dic1 = [NSDictionary dictionaryW...

ios基础之UITableViewCell的重用(带示例原创)

之前一个月刚刚系统的开始接触IOS开发,对UI控件大体了解了一遍,但是因为没有实际的参与项目,对细枝末节的还是不很清楚。 昨天突然想到:UITableViewCell的重用到底是怎么回事,上网查了许多资料后略有体会,但大都差不多,于是想自己实验一下。 便新建了个single view的工程,在storyboard上拖了个tableview,用最基础的方法绑...