When creating a new iOS project in Xcode 12 a UISceneDelegate
is added automatically. Since my App should be available on iOS 11+ (which does not support UISceneDelegate
) I had to remove it.
Removing the UISceneDelegate
from info.plist
and from the AppDelegate
was no problem of course. However I wonder if I have to add any code to application(_: didFinishLaunchingWithOptions)
In most tutorial I found this method is simply left empty, only var window: UIWindow?
had to be added. Other sources show that some setup code has to be added.
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
/* Manual Setup */
// let window = UIWindow(frame: UIScreen.main.bounds)
// window.rootViewController = ViewController() // Your initial view controller.
// window.makeKeyAndVisible()
// self.window = window
return true
}
}
In my tests everything works fine without any additional setup code. The rootViewController is loaded automatically from Storyboard and everything works fine.
Is this just coincident, is this some Xcode magic happening in the background (adding rootVC automatically if code is missing), or is my code (without setup) broken and will eventually fail at some very bad moment
You only need to make sure
1- UISceneDelegate
is deleted
2- Key UIApplicationSceneManifest
is removed from Info.plist
3- These methods are removed from AppDelegate
// MARK: UISceneSession Lifecycle
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)
}
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.
}
4- Add var window: UIWindow?
to AppDelegate
5- Make sure entry point vc is selected in Main.storyboard
After that Don't worry of anything and leave didFinishLaunchingWithOptions
empty as if there is no change happened in Xcode 11