相關知識:
https://blog.csdn.net/BUG_delete/article/details/103699563
'AppDelegate' is only available in iOS 13.0 or newer
The correct code is
let appDelegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate
add @UIApplicationMain this as well.
remove ().
It seems you might set the following
@available(iOS x.x, *)
@UIApplicationMain
In your AppDelegate
you can remove that or you can change the minimum deployment target with your supportive iOS
version
比如公司現在新開一個項目,使用此App的最低版本要求是iOS12。
(也就是說這個App上架后,只有iPhone的iOS版本是12以上的用戶才能在App Store里面看到並下載)
這個時候如果我們使用的是最新版Xcode11並且只按默認配置開發的話,會出現以下錯誤:
'ConnectionOptions' is only available in iOS 13.0 or newer 'UIScene' is only available in iOS 13.0 or newer 'UISceneConfiguration' is only available in iOS 13.0 or newer 'UISceneSession' is only available in iOS 13.0 or newer 'UIWindowScene' is only available in iOS 13.0 or newer ...

需要做一些小小的改動:
1.新建項目時,在User Interface這里選擇Storyboard

說明:
Xcode11默認使用SwiftUI來做App的界面,但SwiftUI這個功能的最低要求版本是iOS13。
目前SwiftUI還有很多地方不太完善,個人建議如果是商業項目的話,還是選擇Storyboard
。因為他目前仍舊是蘋果性價比比較高的一種快速開發界面的方法(較成熟+上手快)。
2.項目target這里的Deployment Target選擇App要求的最低版本,比如上文提到的iOS12

說明:
這個相信大家應該輕車熟路了:App要求的最低版本是多少,這里就選多少,不再贅述。
本以為這樣就差不多了吧。
Surprise!編譯之后錯誤依舊
[圖片上傳中...(image-308aec-1571841138041-7)]
<figcaption></figcaption>
罪魁禍首其實就是這兩個文件:AppDelegate.swift
和SceneDelegate.swift
。
關於iOS13有改動或新登場的這兩個文件,在我的每個教程的SwiftUI部分都有講到,歡迎大家來捧捧場: m.cctalk.com/inst/s9vfhe…

好,繼續。
3.從左邊的錯誤點進去或者直接點目錄進入AppDelegate.swift
文件,拉到最后的兩個方法那里:
第一個方法--隨便點擊其中一個錯誤的紅圈白點
選擇Add @available attribute to enclosing instance method
,點Fix

第二個方法同理。
說明:
--從錯誤的字面意義上就可以得知,無非就是一些類型只能在iOS13上使用,我們現在要在低版本的iOS上使用,他自然不干。
--Add @available attribute to enclosing instance method
的意思是:在class的某個方法前面加上@available(iOS 13.0, *)
,表明只有版本大於等於iOS13的時候才加載這個方法。

--因為AppDelegate.swift
里的didFinishLaunchingWithOptions
方法是無論什么版本的iOS都需要用的,所以我們在Fix的時候不能選擇Add @available attribute to enclosing class
(在整個class前面加上@available(iOS 13.0, *)
)
4.從左邊的錯誤點進去或者直接點目錄進入SceneDelegate.swift
文件,選擇任意一個紅圈白點,點擊Add @available attribute to enclosing class
的Fix

說明:
SceneDelegate.swift
文件是iOS13新登場的,所以給整個class加上@available(iOS 13.0, *)
是OK的:

好
選擇低於iOS13版本的模擬器或者真機運行之后,還是不行:
黑屏
並且控制台會出現:
The app delegate must implement the window property if it wants to use a main storyboard file
原因:
在iOS13中,AppDelegate
把iOS13之前的那些管理整個App生命周期等的任務都委托給了SceneDelegate
,所以原來AppDelegate
的window
屬性自然也就跑到SceneDelegate
里面去了:

而這個SceneDelegate
class又被我們標注了只能iOS13可以用,也就是說iOS13以下版本的iPhone是不會執行整個SceneDelegate
class的代碼的,所以在低版本中系統就找不到window
屬性。
解決方案:
在AppDelegate
的class里面聲明window
屬性:

其實很容易理解,窗口沒了,我們自然看不到外面的風景了,取而代之的就是黑屏
這樣之后:
iOS13以下版本的時候,window
就走AppDelegate
這里,不會黑屏;
iOS13或以上版本的時候,window
就走SceneDelegate
(被委托人)這里,不會黑屏;
原文:https://www.jianshu.com/p/3de524451fe0