After adding SceneDelegate to my Flutter iOS project I started getting a black screen when the app launched. I added the SceneDelegate by creating a file called SceneDelegate.swift with the following code.
import Flutter
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
guard let windowScene = scene as? UIWindowScene else {
return
}
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
preconditionFailure("unable to obtain AppDelegate")
}
let window = UIWindow(windowScene: windowScene)
let flutterEngine = FlutterEngine(name: "FlutterEngine")
flutterEngine.run()
GeneratedPluginRegistrant.register(with: flutterEngine)
let viewController = FlutterViewController(
engine: flutterEngine,
nibName: nil,
bundle: nil
)
window.rootViewController = viewController
window.makeKeyAndVisible()
self.window = window
}
}
My AppDelegate looks like this
import Flutter
import UIKit
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
guard #available(iOS 13, *) else{
let flutterEngine = FlutterEngine(name: "FlutterEngine")
flutterEngine.run()
GeneratedPluginRegistrant.register(with: flutterEngine)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
And my info.plist looks like this
.
.
.
UIApplicationSceneManifest
UIApplicationSupportsMultipleScenes
UISceneConfigurations
UIWindowSceneSessionRoleApplication
UISceneDelegateClassName
$(PRODUCT_MODULE_NAME).SceneDelegate
.
.
.
I am only supporting iOS version 14 and above.
I tried seeing if the code inside the SceneDelegate gets executed by adding log statements and the code does in fact execute. Despite this the screen is black.
I also tried reproducing this issue in a fresh Flutter project but could not do it. Everything worked fine in the fresh project. So it is specific to my Flutter project. I would like to know if I am missing any steps required for adding a SceneDelegate to my app.