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?
Creating an app with Xcode 11 has a little bit of a hidden issue, it does not allow you to run the app on iOS 12 or lower out of the box. There are a few changes that need to be made in order to get your app to work on the older versions of iOS.
Starting in Xcode 13.2, Swift's new suite of concurrency features are now backward compatible all the way back to iOS 13, macOS Catalina, watchOS 6, and tvOS 13. The new concurrency features include async/await, actors, structured concurrency, async sequences, and more.
Backward compatibility property allows the app to use the interface of its older version. If the developers have used several tools for both backward and forward compatibility of your iOS app, it will fail to work with the new iOS 13. For that reason, and the app update is essential.
SwiftUI runs on iOS 13, macOS 10.15, tvOS 13, and watchOS 6, or any future later versions of those platforms. This means if you work on an app that must support iOS N-1 or even N-2 – i.e., the current version and one or two before that – then you will be limited in terms of the features you can offer.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With