惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
小众软件
小众软件
GbyAI
GbyAI
B
Blog RSS Feed
月光博客
月光博客
A
About on SuperTechFans
Microsoft Security Blog
Microsoft Security Blog
Blog — PlanetScale
Blog — PlanetScale
U
Unit 42
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Vercel News
Vercel News
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
雷峰网
雷峰网
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
博客园_首页
G
Google Developers Blog

Oragekk's Blog

A2UI:当 AI Agent 开始直接生成界面 OpenSpec 技术分享:用规格驱动 AI 编程 ChatGPT&Codex订阅教程 一个 waline 评论系统bug引发的思考 Jenkins 远程触发构建踩坑记 Git SSH 密钥配置 初识Rust vuepress-plugin-meting2 谷歌发布多平台应用开发神器Project IDX!PaLM 2加持 Vue常见优化手段 Vue2响应式原理解析 Dart 中的并发 Flutter 工作原理 如何利用GitHub Action提交URL到搜索引擎 提交URL到搜索引擎(百度、Bing、Google) GitHub Actions 使用介绍 素材设计 前端-Q&A 浏览器的事件循环 你不知道的 CSS 之包含块 CSS 属性计算过程 Vercel deploy忽略指定分支 评论插件 Waline 之邮件通知配置 公开API 终端究极美化iTerm2+Pure 使用Bing API提交网站URL Flutter 基础大集合 关于本站 关于本站 关于我
iOS程序启动原理(下)
Oragekk · 2016-12-31 · via Oragekk's Blog

接上篇

iOS 程序启动原理(上)

下图是一个 iOS 程序启动的完整过程

图

main 函数中执行了一个 UIApplicationMain 这个函数.

  int main(int argc, char * argv[])
  {    
    @autoreleasepool {        
      return UIApplicationMain(argc, argv, nil, NSStringFromClass([JNAppDelegate class]));    
    }
   }
  int UIApplicationMain(int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName);

argc, argv:直接传递给 UIApplicationMain 进行相关处理即可;

principalClassName:指定应用程序类名(app 象征),该类必须是 UIApplication(或子类).如果为 nil,则用 UIApplication 类作为默认值.

delegateClassName:指定应用程序的代理类,该类必须遵守 UIApplicationDelegate 协议.

UIApplicationMain 函数会根据 principalClassName 创建 UIApplication 对象,根据 delegateClassName 创建一个 delegate 对象,并将该 delegate 对象赋值给 UIApplication 对象中的 delegate 属性.

接着会建立应用程序的 Main Runloop(事件循环),进行事件的处理(首先会在程序启动完毕后调用 delegate 对象的 application:didFinishLaunchingWithOptions:方法)

程序正常退出时 UIApplicationMain 函数才返回.