62

I have created the iOS Project in Xcode 11.1. I need to remove scene delegate from the application.

6 Answers6

136

You need to do the following steps:

  1. Remove Scene delegate methods from App Delegate and delete the Scene delegate file.
  2. You need to remove UIApplicationSceneManifest from Info.plist.

You also need to add var window:UIWindow? if it is not present in AppDelegate

Manav
  • 2,284
  • 1
  • 14
  • 27
46
  1. Remove SceneDelegate.swift file
  2. Remove Application Scene Manifest from Info.plist file
  3. Add var window: UIWindow? to AppDelegate.swift
  4. Replace @main with @UIApplicationMain
  5. Remove UISceneSession Lifecycle ( functions ) in AppDelegate
23

It is a complete solution for empty project generated with Xcode (with storyboard)

  1. Remove SceneDelegate.swift file
  2. Remove Application Scene Manifest from Info.plist file
  3. Paste this code to your AppDelegate.swift file

import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window:UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        self.window = UIWindow(frame: UIScreen.main.bounds)
        window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
        window?.makeKeyAndVisible()

        return true
    }
}
milczi
  • 7,064
  • 2
  • 27
  • 22
13

Adding on to milzi's answer

  1. Remove SceneDelegate.swift file
  2. Remove Application Scene Manifest from Info.plist file
  3. Remove UISceneSession Lifecycle function from your AppDelegate class
  4. Add var window: UIWindow? in your AppDelegate class as a instance property
  5. Replace @main attribute with @UIApplicationMain attribute (This saves as to manually create and assign window)

Below is how you how your AppDelegate should look like after changes:

import UIKit

@UIApplicationMain
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
    }


}
Amit Samant
  • 13,257
  • 2
  • 10
  • 16
12

To add to accepted answer: you also need to write this in your AppDelegate:

 self.window = UIWindow(frame: UIScreen.main.bounds)
 let controller = MyRootViewController()
 window?.rootViewController = controller
 window?.makeKeyAndVisible()
aturan23
  • 4,798
  • 4
  • 28
  • 52
Alexandra
  • 224
  • 2
  • 5
1

Just in case if you are developing in Objective-C, add window property in the AppDelegate.h file like this:

@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end

No need to initialise the window. It will work automatically.

HAK
  • 2,023
  • 19
  • 26