iOSのアプリケーションライフサイクルは、OSによって変化する

# アプリケーションライフサイクルについて

## 起動時処理
アプリケーションの起動処理は、iOSのバージョンによって変化する！んなアホなw

メモ追加　iOS14では13と同じだった。

### iOS11 / iOS12 では
-[AppDelegate application:didFinishLaunchingWithOptions:]
-[ViewController viewDidLoad]
-[ViewController viewWillAppear:]
-[ViewController viewDidAppear:]
-[AppDelegate applicationDidBecomeActive:]
-[ViewController applicationDidBecomeActiveNotification:]
 
### iOS13 では
-[AppDelegate application:didFinishLaunchingWithOptions:]
-[ViewController viewDidLoad]
-[ViewController viewWillAppear:]
-[AppDelegate applicationDidBecomeActive:]
-[ViewController applicationDidBecomeActiveNotification:]
-[ViewController viewDidAppear:]
 

の順で呼ばれます。ちなみにiOS10以前はさらに違うとかいう。。。

## エビデンス
xcode10 iOS11.4

```
2020-05-29 11:46:12.600729+0900 LifeCycleCheck[35138:1466107] iOS 11.400000
2020-05-29 11:46:12.600821+0900 LifeCycleCheck[35138:1466107] -[AppDelegate application:didFinishLaunchingWithOptions:]
2020-05-29 11:46:12.602435+0900 LifeCycleCheck[35138:1466107] -[ViewController viewDidLoad]
2020-05-29 11:46:12.602581+0900 LifeCycleCheck[35138:1466107] -[ViewController viewWillAppear:]
2020-05-29 11:46:12.605137+0900 LifeCycleCheck[35138:1466107] -[ViewController viewDidAppear:]
2020-05-29 11:46:12.605948+0900 LifeCycleCheck[35138:1466107] -[AppDelegate applicationDidBecomeActive:]
2020-05-29 11:46:12.606352+0900 LifeCycleCheck[35138:1466107] -[ViewController applicationDidBecomeActiveNotification:]
``` 

xcode10 iOS12.4

``` 
2020-05-29 11:47:46.736811+0900 LifeCycleCheck[35261:1468750] iOS 12.400000
2020-05-29 11:47:46.736906+0900 LifeCycleCheck[35261:1468750] -[AppDelegate application:didFinishLaunchingWithOptions:]
2020-05-29 11:47:46.738585+0900 LifeCycleCheck[35261:1468750] -[ViewController viewDidLoad]
2020-05-29 11:47:46.738806+0900 LifeCycleCheck[35261:1468750] -[ViewController viewWillAppear:]
2020-05-29 11:47:46.742394+0900 LifeCycleCheck[35261:1468750] -[ViewController viewDidAppear:]
2020-05-29 11:47:46.743475+0900 LifeCycleCheck[35261:1468750] -[AppDelegate applicationDidBecomeActive:]
2020-05-29 11:47:46.743871+0900 LifeCycleCheck[35261:1468750] -[ViewController applicationDidBecomeActiveNotification:]
``` 


xcode10 iOS13.0 (xcode11でSDKをダウンロードしてあげればシミュレーターに追加される）

``` 
2020-05-29 12:12:46.661083+0900 LifeCycleCheck[36060:1593933] iOS 13.000000
2020-05-29 12:12:46.661225+0900 LifeCycleCheck[36060:1593933] -[AppDelegate application:didFinishLaunchingWithOptions:]
2020-05-29 12:12:46.664196+0900 LifeCycleCheck[36060:1593933] -[ViewController viewDidLoad]
2020-05-29 12:12:46.664434+0900 LifeCycleCheck[36060:1593933] -[ViewController viewWillAppear:]
2020-05-29 12:12:46.667466+0900 LifeCycleCheck[36060:1593933] -[AppDelegate applicationDidBecomeActive:]
2020-05-29 12:12:46.667834+0900 LifeCycleCheck[36060:1593933] -[ViewController applicationDidBecomeActiveNotification:]
2020-05-29 12:12:46.669859+0900 LifeCycleCheck[36060:1593933] -[ViewController viewDidAppear:]
``` 

xcode11 iOS11

``` 
2020-05-29 11:56:19.988230+0900 LifeCycleCheck[35396:1480682] iOS 11.400000
2020-05-29 11:56:19.988305+0900 LifeCycleCheck[35396:1480682] -[AppDelegate application:didFinishLaunchingWithOptions:]
2020-05-29 11:56:19.989775+0900 LifeCycleCheck[35396:1480682] -[ViewController viewDidLoad]
2020-05-29 11:56:19.989889+0900 LifeCycleCheck[35396:1480682] -[ViewController viewWillAppear:]
2020-05-29 11:56:19.992102+0900 LifeCycleCheck[35396:1480682] -[ViewController viewDidAppear:]
2020-05-29 11:56:19.992871+0900 LifeCycleCheck[35396:1480682] -[AppDelegate applicationDidBecomeActive:]
2020-05-29 11:56:19.993288+0900 LifeCycleCheck[35396:1480682] -[ViewController applicationDidBecomeActiveNotification:]
``` 

xcode11 / iOS12.4 / iOS Development Target 11.0

``` 
2020-05-29 11:57:52.226358+0900 LifeCycleCheck[35522:1484049] libMobileGestalt MobileGestalt.c:890: MGIsDeviceOneOfType is not supported on this platform.
2020-05-29 11:57:52.331236+0900 LifeCycleCheck[35522:1484049] iOS 12.400000
2020-05-29 11:57:52.331356+0900 LifeCycleCheck[35522:1484049] -[AppDelegate application:didFinishLaunchingWithOptions:]
2020-05-29 11:57:52.333709+0900 LifeCycleCheck[35522:1484049] -[ViewController viewDidLoad]
2020-05-29 11:57:52.333902+0900 LifeCycleCheck[35522:1484049] -[ViewController viewWillAppear:]
2020-05-29 11:57:52.339810+0900 LifeCycleCheck[35522:1484049] -[ViewController viewDidAppear:]
2020-05-29 11:57:52.341236+0900 LifeCycleCheck[35522:1484049] -[AppDelegate applicationDidBecomeActive:]
2020-05-29 11:57:52.341763+0900 LifeCycleCheck[35522:1484049] -[ViewController applicationDidBecomeActiveNotification:]
``` 

xcode11 iOS13

``` 
2020-05-29 11:59:10.355521+0900 LifeCycleCheck[35538:1485983] iOS 13.500000
2020-05-29 11:59:10.355631+0900 LifeCycleCheck[35538:1485983] -[AppDelegate application:didFinishLaunchingWithOptions:]
2020-05-29 11:59:10.357546+0900 LifeCycleCheck[35538:1485983] -[ViewController viewDidLoad]
2020-05-29 11:59:10.366342+0900 LifeCycleCheck[35538:1485983] -[ViewController viewWillAppear:]
2020-05-29 11:59:10.370705+0900 LifeCycleCheck[35538:1485983] -[AppDelegate applicationDidBecomeActive:]
2020-05-29 11:59:10.370957+0900 LifeCycleCheck[35538:1485983] -[ViewController applicationDidBecomeActiveNotification:]
2020-05-29 11:59:10.380553+0900 LifeCycleCheck[35538:1485983] -[ViewController viewDidAppear:]
``` 

本来はiOS13ではSceneDelegateという新しいライフサイクルが採用されたので、そちらを使うように推奨されていますが、SceneDelegateに対応しても同じです。

iOS13 with SceneDelegate

``` 
2020-05-29 14:38:52.530976+0900 SceneAndAppCycle[41137:1737558] -[AppDelegate application:didFinishLaunchingWithOptions:]
2020-05-29 14:38:52.556082+0900 SceneAndAppCycle[41137:1737558] -[SceneDelegate scene:willConnectToSession:options:]
2020-05-29 14:38:52.558660+0900 SceneAndAppCycle[41137:1737558] -[ViewController viewDidLoad]
2020-05-29 14:38:52.566500+0900 SceneAndAppCycle[41137:1737558] -[ViewController viewWillAppear:]
2020-05-29 14:38:52.568473+0900 SceneAndAppCycle[41137:1737558] -[SceneDelegate sceneWillEnterForeground:]
2020-05-29 14:38:52.570589+0900 SceneAndAppCycle[41137:1737558] -[SceneDelegate sceneDidBecomeActive:]
2020-05-29 14:38:52.571262+0900 SceneAndAppCycle[41137:1737558] -[ViewController applicationDidBecomeActiveNotification:]
2020-05-29 14:38:52.581489+0900 SceneAndAppCycle[41137:1737558] -[ViewController viewDidAppear:]
``` 

## バックグラウンド移行時
-[AppDelegate applicationWillResignActive:]
-[ViewController applicationWillResignActiveNotification:]
-[AppDelegate applicationDidEnterBackground:]
-[ViewController applicationDidEnterBackgroundNotification:]
 
## バックグラウンドからの復帰時
-[AppDelegate applicationWillEnterForeground:]
-[AppDelegate applicationDidBecomeActive:]
-[ViewController applicationDidBecomeActiveNotification:]