[SwiftUI]工程最低适配iOS13

问题:

新建工程,选择最低支持iOS13报错:

'main()' is only available in iOS 14.0 or newer

'Scene' is only available in iOS 14.0 or newer

'WindowGroup' is only available in iOS 14.0 or newer

解决:

注释掉上面代码,重新创建一个AppDelegate作为入口:

Swift 复制代码
import Foundation
import SwiftUI

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // 创建一个UIHostingController来托管你的ContentView
        let contentView = ContentView()

        // 设置window
        let window = UIWindow(frame: UIScreen.main.bounds)
        window.backgroundColor = .white
        window.rootViewController = UIHostingController(rootView: contentView)
        self.window = window
        window.makeKeyAndVisible()
        return true
    }
}

info.plist中移除Application Scene Manifest

然后,重新运行就没问题了

相关推荐
Wenzar_15 小时前
# 发散创新:SwiftUI 中状态管理的深度实践与重构艺术 在 SwiftUI 的世界里,**状态驱动 UI 是核心哲学**。但随
java·python·ui·重构·swiftui
大熊猫侯佩2 天前
GeometryReader 生存指南(下集):与恶魔共舞——陷阱、禁忌与最终救赎
swiftui·performance·layout·frame·stack·geometryreader·preferencekey
大熊猫侯佩2 天前
别被系统绑架:SwiftUI List 替换背后的底层逻辑
swiftui·swift·apple
东坡肘子4 天前
从 OpenSwiftUI 到 DanceUI:换个方式 Dive SwiftUI -- 肘子的 Swift 周报 #132
人工智能·swiftui·swift
用户79457223954135 天前
【SwiftyJSON】拯救你的 as? [String: Any]——链式 JSON 访问的正确姿势
swiftui·objective-c·swift
用户79457223954135 天前
【Moya】为什么你的 Alamofire 代码需要再封装一层?
swiftui·objective-c·swift
空中海5 天前
第二章:SwiftUI 视图基础
ios·swiftui·swift
择势5 天前
MVVM 本质解构 + RxSwift 与 Combine 深度对决与选型指南
swiftui·swift·rxswift
东坡肘子11 天前
被 Vibe 摧毁的版权壁垒,与开发者的新护城河 -- 肘子的 Swift 周报 #131
人工智能·swiftui·swift