我无法在Xcode 12上为旧的iOS版本编程创建应用程序。这是我在appdelegate。swift
中的代码@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Set the window bounds
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = UINavigationController(rootViewController: ViewController())
return true
}
}
这是我的ViewController:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.backgroundColor = .white
}
}
我在网上寻找解决方案,但找不到。我删除了Main。storyboard和SceneDelegate.swift文件。我删除键/值main in info。plist文件。然后移除Main。storyboard到主界面
不要删除sceneDelegate文件,这是一个不好的做法,appDelegate很快就会被弃用…如果你需要安装设备,请使用iOS 12或更早的版本。
在sceneDelegate…
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let scene = (scene as? UIWindowScene) else { return }
let floatVersion = (UIDevice.current.systemVersion as NSString).floatValue
if floatVersion >= 13 {
window = UIWindow(windowScene: scene)
window?.makeKeyAndVisible()
let controller = YourController()
let navigation = UINavigationController(rootViewController: controller)
window?.rootViewController = navigation
}
}
并在appDelegate中使用它。仅适用于iOS 12或更早版本的设备
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let floatVersion = (UIDevice.current.systemVersion as NSString).floatValue
if floatVersion <= 12.5 {
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
// if you use a navigation...
let controller = YourController()
let navigation = UINavigationController(rootViewController: controller)
window?.rootViewController = navigation
}
return true
}
尝试在场景委托和appDelegate的验证中使用断点,使用模拟器与iOS 12版本,iOS 13版本或最新版本…并将工作,但不要删除sceneDelegate,查看wwdc swift新闻。
我有同样的问题2年前,我使用这个选项,目前仍然为我工作,我希望这将帮助。