【问题标题】:Cannot add iOS support for versions previous to 13 in Xcode 11无法在 Xcode 11 中为 13 之前的版本添加 iOS 支持
【发布时间】:2020-06-08 23:17:43
【问题描述】:

我已经以两种方式遵循this tutorial,通过实现@available 指令和删除代码/文件,但仍然显示黑屏。除非我遗漏了什么,否则我认为这两件事我都做得很好。

这是删除文件/代码方式的当前状态:

SceneDelegate.swift 已删除。

AppDelegate.swift 像这样:

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
}



}

最后是这样的 Info.plist:

由于程序不支持 iOS 13 之前的版本,我错过了什么,所以屏幕仍然显示为黑色?

【问题讨论】:

    标签: swift xcode ios13 uiwindow


    【解决方案1】:

    在您的 AppDelegate 文件中的 didFinishLaunchingWithOptions 方法中添加此代码

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
    
        if #available(iOS 13.0, *) {
    
        } else {
            let rootVC = //Initialize root controller
            self.window?.rootViewController = rootVC
            self.window?.makeKeyAndVisible()
        }
        return true
    }
    

    【讨论】:

      【解决方案2】:

      我一步一步指导你。

      1. 第一次从项目中删除 SceneDelegate 文件。
      2. var window: UIWindow? 添加到 AppDelegate。
      3. 从 AppDelegate 中移除下面的函数。

        // MARK:UISceneSession 生命周期

        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. Info.plist 文件中删除 Application Scene Manifest 键。

      5. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let navigation = UINavigationController(rootViewController: ViewController()) let frame = UIScreen.main.bounds window = UIWindow(frame: frame) window!.rootViewController = navigation window!.makeKeyAndVisible() return true }

      额外

      AppDelegate 文件中的 didFinishLaunchingWithOptions

      下方添加委托方法
          func applicationWillResignActive(_ application: UIApplication) {
              // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
              // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
          }
      
          func applicationDidEnterBackground(_ application: UIApplication) {
              // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
              // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
          }
      
          func applicationWillEnterForeground(_ application: UIApplication) {
              // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
          }
      
          func applicationDidBecomeActive(_ application: UIApplication) {
              // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
          }
      
          func applicationWillTerminate(_ application: UIApplication) {
              // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
          }
      

      【讨论】:

        猜你喜欢
        • 2021-06-27
        • 2020-01-27
        • 2022-08-24
        • 2019-07-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-26
        • 1970-01-01
        相关资源
        最近更新 更多