必须要清楚的前提概念:
app启动之后就进来这里了啊,或者说启动也是在这个的范畴啊,【任何生命状态的转变,UIKit都会通知委托对象XXXDelegate】
1、As your app changes from state to state, you must adjust its behavior accordingly. 状态决定行为
-
In iOS 13 and later, use UISceneDelegate objects to respond to life-cycle events in a scene-based app. #基于场景
-
In iOS 12 and earlier, use the
UIApplicationDelegate
object to respond to life-cycle events. #基于app
-- app有foreground、 background、unattended 三种大状态,然后还有活跃与非活跃状态,详细看文档,我还没看完啊。
而你应该在每种状态中定义响应的行为,是什么人就做什么事
-- iOS 13 及之后都是用
UISceneDelegate
这个对象来代表你的app的生命周期,所以 iOS 12 及以前就是用
UIApplicationDelegate
了咯
-- 所以 iOS 13 是基于 场景(scene) 的生命周期事件 Respond to Scene-Based Life-Cycle Events
而 iOS12 则是基于app的生命周期事件 Respond to App-Based Life-Cycle Events
苹果更新快,所以代码的迭代周期也快啊,可能ios14又不一样了啊
Respond to Scene-Based Life-Cycle Events(基于场景的生命周期 ):
- If your app supports scenes, UIKit delivers separate life-cycle events for each. 每一个场景,每一个生命
--The user can create multiple scenes for each app, and show and hide them separately
你可以为一个app创建多个scene,每一个scene都有自己的生命周期,是一个独立生命体,象征一个UI
--Scene support is an opt-in feature. To enable basic support, add the UIApplicationSceneManifest key to your app’s
Info.plist
file as described in Specifying the Scenes Your App Supports.scene是一个可选特征,你需要在app’s
Info.plist文本中选择使用scene机制
生命周期:
启动阶段 launch time ,是app准备时期,此时的生命状态为unattached
㊀ --At launch time, the system starts your app in the inactive state before transitioning it to the foreground.
在启动阶段 进入的inactive状态:在进入foreground状态之前,iOS会将你的app置于inactive状态,亦即是foreground的闲置状态,启动阶段的inactive状态下,UIKit会调用 委托对象 的这两个方法: