[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

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

相关推荐
用户091 天前
SwiftUI Charts 函数绘图完全指南
ios·swiftui·swift
东坡肘子2 天前
完成 Liquid Glass 的适配了吗?| 肘子的 Swift 周报 #0102
swiftui·swift·apple
大熊猫侯佩4 天前
iOS 26 仅需几行代码让 SwiftUI 7 液态玻璃界面焕发新春
前端·swiftui·apple
东坡肘子9 天前
从开放平台到受控生态:谷歌宣布 Android 开发者验证政策 | 肘子的 Swift 周报 #0101
android·swiftui·swift
HarderCoder10 天前
深入理解 SwiftUI 的 Structural Identity:为什么“换个条件分支”就会丢状态?
swiftui·swift
YungFan10 天前
Swift 6.2 新特性
swiftui·swift
大熊猫侯佩14 天前
当液态玻璃计划遭遇反叛者:一场 iOS 26 界面的暗战
swiftui·xcode·apple
雪糕吖14 天前
SwiftUI 自定义 Shape:实现顶部圆角矩形 RoundedTopRectangle
ios·swiftui
东坡肘子16 天前
写给这段旅程,也写给未来的自己 | 肘子的 Swift 周报 #0100
swiftui·swift·apple
大熊猫侯佩22 天前
SwiftUI 三阵诀:杨过绝情谷悟 “视图布阵” 之道
swiftui·swift·apple