[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作为入口:

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

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

注意:

如果需要支持跨平台还是乖乖最低支持iOS14

使用 @UIApplicationMain 并定义一个继承自 UIResponder 和遵循 UIApplicationDelegate 协议的 AppDelegate 类是 UIKit 应用程序的传统启动方式,它专门用于 iOS 和 iPadOS 平台。这段代码不能直接用于跨平台运行,因为它仅适用于 iOS 和 iPadOS,并且使用了 UIKit 的特定类和方法,比如 UIWindow 和 UIHostingController

建议:

强烈建议不要管iOS13,最低适配到iOS14。现在iOS15之下的设备只占3%,这3%中还包含iOS14在其中。就我的感受而言,SwiftUI兼容不兼容iOS13完全就像是两种工作量。

iOS17出来前:

iOS17出来后到现在:

数据来源: https://mixpanel.com/trends

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值