0

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.

1 Answers1

0

A big cheat: I got tired of trying to display another screen in AppDelegate and then run the FlutterEngine in SceneDelegate. I spent the better part of a day on it and got nowhere.

The solution I came upon was to set the background of LaunchScreen in Xcode to black. Then the LaunchScreen comes up with the logo (or whatever) on a black background, then it goes to black, then the screen comes up.

I hope someone comes up with a better solution but I don't have anymore cycles to burn on the splash screen.

starball
  • 20,030
  • 7
  • 43
  • 238
Boggle
  • 97
  • 1
  • 6