In Xcode 11, I created a new app project from the Single View App template. I want this app to run in iOS 12 as well as iOS 13. But when I switch the deployment target to iOS 12, I got a lot of error messages like this one:
UIWindowScene is only available in iOS 13 or newer
What should I do?
The template in Xcode 11 uses a scene delegate. Scene delegates and the related classes are new in iOS 13; they don't exist in iOS 12 and before, and the launch process is different.
To make a project generated from an Xcode 11 app template backward compatible, you need to mark the entire SceneDelegate class, and any methods in the AppDelegate class that refer to UISceneSession, as @available(iOS 13.0, *)
.
You also need to declare a window
property in the AppDelegate class (if you don't do that, the app will run and launch but the screen will be black):
var window : UIWindow?
The result is that when this app runs in iOS 13, the scene delegate has the window
, but when it runs in iOS 12 or before, the app delegate has the window
— and your other code may then need to take account of that in order to be backward compatible.