Xcode 11 backward compatibility: "UIWindowScene is only available in iOS 13 or newer"
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.
Could you please add this line code like the following
STEP1:-
@available out the SceneDelegate.swift
@available(iOS 13.0, *)class SceneDelegate: UIResponder, UIWindowSceneDelegate {//...}
STEP2:-
@available out some methods in AppDelegate.swift
// AppDelegate.swift@available(iOS 13.0, *)func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)}@available(iOS 13.0, *)func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { // Called when the user discards a scene session. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. // Use this method to release any resources that were specific to the discarded scenes, as they will not return.}
STEP3:-
You should declare window property in AppDelegate.swift file like var window: UIWindow?
class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true }