发布时黑屏:如何在应用程序和场景代理中支持iOS 10和iOS 13以上的所有版本

发布时黑屏:如何在应用程序和场景代理中支持iOS 10和iOS 13以上的所有版本,ios,swift,ios13,appdelegate,Ios,Swift,Ios13,Appdelegate,我的应用程序支持iOS 10.0及更高版本。当我尝试在iOS 13中启动我的应用程序时,它会显示一个黑色窗口。当我移除场景代理时,它会配置初始ViewController并显示标签。在iOS 12及以下版本中,只要使用App delegate,一切都可以正常工作 在我的应用程序代理中: @main class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func

我的应用程序支持iOS 10.0及更高版本。当我尝试在iOS 13中启动我的应用程序时,它会显示一个黑色窗口。当我移除场景代理时,它会配置初始ViewController并显示标签。在iOS 12及以下版本中,只要使用App delegate,一切都可以正常工作

在我的应用程序代理中:

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        configureInitialViewController()
        return true
    }

    func configureInitialViewController()
    {
        var initialVC: UIViewController
        let mainsb = UIStoryboard(name: "Main", bundle: nil)
        if Auth.auth().currentUser != nil {
            //print("successfully signed in")
            initialVC = mainsb.instantiateViewController(withIdentifier: IDENTIFIER_MAIN_TABBAR)
        } else {
            //print("successfully signed out")
            initialVC = mainsb.instantiateViewController(withIdentifier: IDENTIFIER_WELCOME_NAV)
        }

        window?.rootViewController = initialVC
        window?.makeKeyAndVisible()
    }
    
    func applicationWillResignActive(_ application: UIApplication) {
        Api.User.isOnline(bool: false)
    }

    // MARK: UISceneSession Lifecycle

    @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.
    }
}
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
        guard let _ = (scene as? UIWindowScene) else { return }
    }

    func sceneWillResignActive(_ scene: UIScene) {
        Api.User.isOnline(bool: false)
        
    }
}
我还删除了info.plist中的应用程序场景清单

有人能帮我检查一下我是否正确设置了版本支持吗

我真的很感激任何帮助

更新:

我在iOS 13.5中测试过它,但不是13.2或14.3。为什么它在不同的版本中表现出不同的行为

In your AppDelegate inside didFinishLaunchingWithOptions add this:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    if #available(iOS 13.0, *){}
    else{
        //Load your vc
    }
    return true
}
然后在SceneDelegate inside中添加以下内容:

@available(iOS 13.0, *)
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
    guard let _ = (scene as? UIWindowScene) else { return }
    guard let windowScene = (scene as? UIWindowScene) else {return}
    let window:UIWindow = UIWindow(windowScene: windowScene)
    self.window = window
    self.window?.rootViewController = // set you VC
    self.window?.makeKeyAndVisible()
    
}

如果从AppDelegate文件中删除SceneDelegate文件和UISceneSession生命周期方法。我想可能吧works@Jigneshmayani谢谢你的建议,我试过了,但在iOS 13及以上版本中显示了一个黑色窗口。我的初始VC已配置,但您是否从AppDelegate文件中删除了UISCenessence生命周期方法?是的,我删除了生命周期方法和scenedelegate.swift。它仍然显示一个*黑色的UI过渡视图。我忘了告诉您,如果您没有从Info.plist中删除应用程序场景清单,请删除它,然后尝试此操作<即使我添加了应用程序场景清单和生命周期方法,也不会调用code>willConnectTo。我想问题可能是我如何将我的初始视图控制器配置为导航控制器您可以共享在XCODE中生成的日志吗?我在willConnectTo中添加了一个打印,但没有日志。。设置一个
窗口?.backgroundColor=UIColor.red
也没有被调用。它在模拟器上工作,但不是真正的设备