博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
APP的启动流程
阅读量:7191 次
发布时间:2019-06-29

本文共 2698 字,大约阅读时间需要 8 分钟。

从 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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

转载于:https://www.cnblogs.com/iQingYang/p/5193186.html

你可能感兴趣的文章
第一冲刺阶段(第一天)
查看>>
C语言
查看>>
【转】火狐下因为margin的存在导致距离顶部总有空白
查看>>
Python中的base64模块
查看>>
Modelsim仿真一些简单问题
查看>>
【HDU 6008】Worried School(模拟)
查看>>
使用ES6的模块编写web页面碰到的坑
查看>>
vim常用命令
查看>>
【计算几何】CDOJ1720 几何几何
查看>>
阿里云挂载数据盘
查看>>
使用selenium模拟浏览器抓取淘宝商品美食信息
查看>>
MongoDB服务无法启动,windows提示发生服务特定错误:100
查看>>
A Simple OpenGL Shader Example
查看>>
资料整理面试
查看>>
理解JavaScript中的事件处理
查看>>
lock: mutex/spinlock/shared lock
查看>>
基于JAVA的身份证实名认证接口调用代码实例
查看>>
Shell命令-文件压缩解压缩之tar、unzip
查看>>
挺有意思的一段VBS代码,让系统阅读/朗读指定文本
查看>>
mysql体系结构
查看>>