区块链技术博客
www.b2bchain.cn

App 生命周期求职学习资料

本文介绍了App 生命周期求职学习资料,有助于帮助完成毕业设计以及求职,是一篇很好的资料。

对技术面试,学习经验等有一些体会,在此分享。

前言

平常用到再想着看,值到学到后台下载部分才意识到APP生命周期掌握的不够系统,这里系统的整理下。本篇博客完全借鉴自苹果官方文档

现在生命周期大致分了两类:Scene-Based 和 App-Based。前者是新出的,用的比较少,这里只看最经典的后者。

总揽

Apple提供的有关生命周期的接口都在UIApplicationDelegate 协议里
App 生命周期

上图便是APP几大状态:Active, Inactive, Background, Suspended, Not Running。关于状态间的转换将一一介绍

下图比上图更清晰一些:
App 生命周期

关于每个状态的详细介绍在这篇博客

APP启动

参考官方文档Responding to the Launch of Your App

启动分两种情况,除了前台打开应用,还有”the system might also launch your app in the background to handle those events. “

URLSession的background-session就会用到第二种情况

详细流程图:
App 生命周期

上图的流程解析见About the App Launch Sequence

具体自行Demo测试:

2020-08-03 20:43:31.782814+0800 AppLifeDemo[73626:37983192] -[AppDelegate application:willFinishLaunchingWithOptions:] 2020-08-03 20:43:31.782921+0800 AppLifeDemo[73626:37983192] 2 2020-08-03 20:43:31.783022+0800 AppLifeDemo[73626:37983192] -[AppDelegate application:didFinishLaunchingWithOptions:] 2020-08-03 20:43:31.783106+0800 AppLifeDemo[73626:37983192] 2 2020-08-03 20:43:31.807619+0800 AppLifeDemo[73626:37983192] -[ViewController loadView] 2020-08-03 20:43:31.807762+0800 AppLifeDemo[73626:37983192] 2 2020-08-03 20:43:31.807875+0800 AppLifeDemo[73626:37983192] -[ViewController viewDidLoad] 2020-08-03 20:43:31.807960+0800 AppLifeDemo[73626:37983192] 2 2020-08-03 20:43:31.815127+0800 AppLifeDemo[73626:37983192] -[ViewController viewWillAppear:] 2020-08-03 20:43:31.815216+0800 AppLifeDemo[73626:37983192] 2 2020-08-03 20:43:31.828833+0800 AppLifeDemo[73626:37983192] -[ViewController viewDidAppear:] 2020-08-03 20:43:31.828941+0800 AppLifeDemo[73626:37983192] 0

关于状态:

typedef NS_ENUM(NSInteger, UIApplicationState) {     UIApplicationStateActive,     UIApplicationStateInactive,     UIApplicationStateBackground } API_AVAILABLE(ios(4.0));

可以看到,直到主View的viewDidAppear后APP状态才变成Active

另外,苹果建议对APP一次性设置放置在willFinishLaunchdidFinishLaunch方法中,且不应该阻塞线程,具体可以参考Performing One-Time Setup for Your App

同时大致介绍了各沙盒目录的用法:

  1. ~/Library/Application Support :Store app-specific files that you want backed up(备份) with the user’s other content. Use this directory for data files, configuration files, document templates, and so on。存放不对外的数据,连接iTunes可以进行备份
  2. ~/Library/Caches :Store temporary data files that can be easily regenerated or downloaded.不进行备份
  3. ~/Library/Preferences:存UserDefaults数据,连接iTunes可以进行备份
  4. ~/tmp :也是存临时文件,不进行备份
  5. ~/Documents:存放可对外的数据,连接iTunes可以进行备份

APP后台启动

App 生命周期

APP从前台退后台

App 生命周期

ViewController的Life-Cycle

loadView

首先明确VC的view是lazy-load的,当需要用到view时如果view为空就会调用VC的loadView方法,load成功然后就会调用viewDidLoad方法。其中loadView里还可以自定义自己的root-view,比如:

    self.webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:[[WKWebViewConfiguration alloc] init]];     self.webView.UIDelegate = self;     self.view = self.webView;

上面代码便会将VC的root-view变为webView

这里一开始可能会有点疑问:为什么在loadView里用到了self.view不会造成循环引用吗?
这是因为self.view = self.webView调用的是setter而不是getter方法

还有一点,loadView里并没有显示写frame,是因为loadView会使root-view的frame自动填充父view

好吧,原来内容那么多,又懒的总结了,以后再说🐶

前言

平常用到再想着看,值到学到后台下载部分才意识到APP生命周期掌握的不够系统,这里系统的整理下。本篇博客完全借鉴自苹果官方文档

现在生命周期大致分了两类:Scene-Based 和 App-Based。前者是新出的,用的比较少,这里只看最经典的后者。

总揽

Apple提供的有关生命周期的接口都在UIApplicationDelegate 协议里
App 生命周期

上图便是APP几大状态:Active, Inactive, Background, Suspended, Not Running。关于状态间的转换将一一介绍

下图比上图更清晰一些:
App 生命周期

关于每个状态的详细介绍在这篇博客

APP启动

参考官方文档Responding to the Launch of Your App

启动分两种情况,除了前台打开应用,还有”the system might also launch your app in the background to handle those events. “

URLSession的background-session就会用到第二种情况

详细流程图:
App 生命周期

上图的流程解析见About the App Launch Sequence

具体自行Demo测试:

2020-08-03 20:43:31.782814+0800 AppLifeDemo[73626:37983192] -[AppDelegate application:willFinishLaunchingWithOptions:] 2020-08-03 20:43:31.782921+0800 AppLifeDemo[73626:37983192] 2 2020-08-03 20:43:31.783022+0800 AppLifeDemo[73626:37983192] -[AppDelegate application:didFinishLaunchingWithOptions:] 2020-08-03 20:43:31.783106+0800 AppLifeDemo[73626:37983192] 2 2020-08-03 20:43:31.807619+0800 AppLifeDemo[73626:37983192] -[ViewController loadView] 2020-08-03 20:43:31.807762+0800 AppLifeDemo[73626:37983192] 2 2020-08-03 20:43:31.807875+0800 AppLifeDemo[73626:37983192] -[ViewController viewDidLoad] 2020-08-03 20:43:31.807960+0800 AppLifeDemo[73626:37983192] 2 2020-08-03 20:43:31.815127+0800 AppLifeDemo[73626:37983192] -[ViewController viewWillAppear:] 2020-08-03 20:43:31.815216+0800 AppLifeDemo[73626:37983192] 2 2020-08-03 20:43:31.828833+0800 AppLifeDemo[73626:37983192] -[ViewController viewDidAppear:] 2020-08-03 20:43:31.828941+0800 AppLifeDemo[73626:37983192] 0

关于状态:

typedef NS_ENUM(NSInteger, UIApplicationState) {     UIApplicationStateActive,     UIApplicationStateInactive,     UIApplicationStateBackground } API_AVAILABLE(ios(4.0));

可以看到,直到主View的viewDidAppear后APP状态才变成Active

另外,苹果建议对APP一次性设置放置在willFinishLaunchdidFinishLaunch方法中,且不应该阻塞线程,具体可以参考Performing One-Time Setup for Your App

同时大致介绍了各沙盒目录的用法:

  1. ~/Library/Application Support :Store app-specific files that you want backed up(备份) with the user’s other content. Use this directory for data files, configuration files, document templates, and so on。存放不对外的数据,连接iTunes可以进行备份
  2. ~/Library/Caches :Store temporary data files that can be easily regenerated or downloaded.不进行备份
  3. ~/Library/Preferences:存UserDefaults数据,连接iTunes可以进行备份
  4. ~/tmp :也是存临时文件,不进行备份
  5. ~/Documents:存放可对外的数据,连接iTunes可以进行备份

APP后台启动

App 生命周期

APP从前台退后台

App 生命周期

ViewController的Life-Cycle

loadView

首先明确VC的view是lazy-load的,当需要用到view时如果view为空就会调用VC的loadView方法,load成功然后就会调用viewDidLoad方法。其中loadView里还可以自定义自己的root-view,比如:

    self.webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:[[WKWebViewConfiguration alloc] init]];     self.webView.UIDelegate = self;     self.view = self.webView;

上面代码便会将VC的root-view变为webView

这里一开始可能会有点疑问:为什么在loadView里用到了self.view不会造成循环引用吗?
这是因为self.view = self.webView调用的是setter而不是getter方法

还有一点,loadView里并没有显示写frame,是因为loadView会使root-view的frame自动填充父view

好吧,原来内容那么多,又懒的总结了,以后再说🐶

前言

平常用到再想着看,值到学到后台下载部分才意识到APP生命周期掌握的不够系统,这里系统的整理下。本篇博客完全借鉴自苹果官方文档

现在生命周期大致分了两类:Scene-Based 和 App-Based。前者是新出的,用的比较少,这里只看最经典的后者。

总揽

Apple提供的有关生命周期的接口都在UIApplicationDelegate 协议里
App 生命周期

上图便是APP几大状态:Active, Inactive, Background, Suspended, Not Running。关于状态间的转换将一一介绍

下图比上图更清晰一些:
App 生命周期

关于每个状态的详细介绍在这篇博客

APP启动

参考官方文档Responding to the Launch of Your App

启动分两种情况,除了前台打开应用,还有”the system might also launch your app in the background to handle those events. “

URLSession的background-session就会用到第二种情况

详细流程图:
App 生命周期

上图的流程解析见About the App Launch Sequence

具体自行Demo测试:

2020-08-03 20:43:31.782814+0800 AppLifeDemo[73626:37983192] -[AppDelegate application:willFinishLaunchingWithOptions:] 2020-08-03 20:43:31.782921+0800 AppLifeDemo[73626:37983192] 2 2020-08-03 20:43:31.783022+0800 AppLifeDemo[73626:37983192] -[AppDelegate application:didFinishLaunchingWithOptions:] 2020-08-03 20:43:31.783106+0800 AppLifeDemo[73626:37983192] 2 2020-08-03 20:43:31.807619+0800 AppLifeDemo[73626:37983192] -[ViewController loadView] 2020-08-03 20:43:31.807762+0800 AppLifeDemo[73626:37983192] 2 2020-08-03 20:43:31.807875+0800 AppLifeDemo[73626:37983192] -[ViewController viewDidLoad] 2020-08-03 20:43:31.807960+0800 AppLifeDemo[73626:37983192] 2 2020-08-03 20:43:31.815127+0800 AppLifeDemo[73626:37983192] -[ViewController viewWillAppear:] 2020-08-03 20:43:31.815216+0800 AppLifeDemo[73626:37983192] 2 2020-08-03 20:43:31.828833+0800 AppLifeDemo[73626:37983192] -[ViewController viewDidAppear:] 2020-08-03 20:43:31.828941+0800 AppLifeDemo[73626:37983192] 0

关于状态:

typedef NS_ENUM(NSInteger, UIApplicationState) {     UIApplicationStateActive,     UIApplicationStateInactive,     UIApplicationStateBackground } API_AVAILABLE(ios(4.0));

可以看到,直到主View的viewDidAppear后APP状态才变成Active

另外,苹果建议对APP一次性设置放置在willFinishLaunchdidFinishLaunch方法中,且不应该阻塞线程,具体可以参考Performing One-Time Setup for Your App

同时大致介绍了各沙盒目录的用法:

  1. ~/Library/Application Support :Store app-specific files that you want backed up(备份) with the user’s other content. Use this directory for data files, configuration files, document templates, and so on。存放不对外的数据,连接iTunes可以进行备份
  2. ~/Library/Caches :Store temporary data files that can be easily regenerated or downloaded.不进行备份
  3. ~/Library/Preferences:存UserDefaults数据,连接iTunes可以进行备份
  4. ~/tmp :也是存临时文件,不进行备份
  5. ~/Documents:存放可对外的数据,连接iTunes可以进行备份

APP后台启动

App 生命周期

APP从前台退后台

App 生命周期

ViewController的Life-Cycle

loadView

首先明确VC的view是lazy-load的,当需要用到view时如果view为空就会调用VC的loadView方法,load成功然后就会调用viewDidLoad方法。其中loadView里还可以自定义自己的root-view,比如:

    self.webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:[[WKWebViewConfiguration alloc] init]];     self.webView.UIDelegate = self;     self.view = self.webView;

上面代码便会将VC的root-view变为webView

这里一开始可能会有点疑问:为什么在loadView里用到了self.view不会造成循环引用吗?
这是因为self.view = self.webView调用的是setter而不是getter方法

还有一点,loadView里并没有显示写frame,是因为loadView会使root-view的frame自动填充父view

好吧,原来内容那么多,又懒的总结了,以后再说🐶

部分转自互联网,侵权删除联系

赞(0) 打赏
部分文章转自网络,侵权联系删除b2bchain区块链学习技术社区 » App 生命周期求职学习资料
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

b2b链

联系我们联系我们