You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS 13+中SceneDelegate是否为必填项?

iOS 13+ 无需 SceneDelegate 开发应用的实现方案

核心结论

iOS 13+ 完全可以不使用 SceneDelegate 开发应用,你“多场景可选但至少需支持一个场景因此SceneDelegate必填”的观点不成立。之前出现空白屏,是因为默认新建的 iOS13+ 项目启用了 Scene 配置,系统会优先走 SceneDelegate 流程,忽略 AppDelegate 中的 window 设置。

具体实现步骤

  • 删除项目中的 SceneDelegate.swift 文件
  • 打开 Info.plist,移除 Application Scene Manifest 整个条目(对应键为 UIApplicationSceneManifest)
  • 修改 AppDelegate.swift,恢复 iOS 13 之前的写法:
    1. 声明 var window: UIWindow? 属性
    2. 在 application(_:didFinishLaunchingWithOptions:) 方法中完成窗口初始化、根视图控制器设置和窗口显示

示例代码(AppDelegate.swift)

import UIKit

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

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // 初始化窗口
        window = UIWindow(frame: UIScreen.main.bounds)
        // 设置根视图控制器(替换为你的实际控制器)
        window?.rootViewController = ViewController()
        // 让窗口成为主窗口并显示
        window?.makeKeyAndVisible()
        return true
    }
}

补充说明

采用这种方式后,应用将回到 iOS 13 之前的单窗口模式,所有应用级生命周期事件(如前后台切换、内存警告等)仍由 AppDelegate 处理,无需依赖 SceneDelegate。

内容的提问来源于stack exchange,提问作者NightFuryLxD

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 05:46:08