PAYATHON 2026

React Native 0.85 在 Xcode 27 启动失败:需 UIScene 生命周期

数据小陈

结论

这是 Xcode 27 所用 iOS SDK 对 UIScene 生命周期的强制检查。JS 层和 New Architecture 本身没有问题。RN 0.85 默认模板仍通过 UIApplicationDelegate 创建 UIWindow,链接新 SDK 后可以编译,但启动时会被 UIKit 拦下。处理方式是在 iOS 原生层补上 UIApplicationSceneManifest,再由 UISceneDelegate 接管窗口和根视图的创建。

原因

UIScene life cycle is required for apps built with this SDK 这条报错说明,应用链接了要求 Scene 生命周期的 SDK。UIApplicationSceneManifest 必须配置;只加清单,却没有把 RN 根视图挂到 scene 的 UIWindow 上,启动后通常会出现黑屏或白屏。New Architecture 仍沿用同一套 UIKit 启动流程,因此迁移点还是在 AppDelegate 和 SceneDelegate。

迁移步骤

  1. 在 iOS 工程的 Info.plist 中加入 Scene Manifest。单窗口应用将 UIApplicationSupportsMultipleScenes 设为 false。
<key>UIApplicationSceneManifest</key>
<dict>
  <key>UIApplicationSupportsMultipleScenes</key>
  <false/>
  <key>UISceneConfigurations</key>
  <dict>
    <key>UIWindowSceneSessionRoleApplication</key>
    <array>
      <dict>
        <key>UISceneConfigurationName</key>
        <string>Default Configuration</string>
        <key>UISceneDelegateClassName</key>
        <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
      </dict>
    </array>
  </dict>
</dict>
  1. 新建 SceneDelegate.swift 并加入 iOS target。这里要让 SceneDelegate 创建 UIWindow(windowScene:),根视图控制器仍由 RN 的工厂创建。下面的示例按 RN 0.85 的 RCTAppDelegate 暴露 reactNativeFactory、moduleName、initialProps 的常见结构编写;如果你的模板方法名不同,以本地头文件为准。
import UIKit
import React
import React_RCTAppDelegate

final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
  var window: UIWindow?

  func scene(_ scene: UIScene,
             willConnectTo session: UISceneSession,
             options connectionOptions: UIScene.ConnectionOptions) {
    guard let windowScene = scene as? UIWindowScene,
          let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
      return
    }

    let rootVC = appDelegate.reactNativeFactory.rootViewController(
      withModuleName: appDelegate.moduleName,
      initialProperties: appDelegate.initialProps,
      launchOptions: nil
    )

    let window = UIWindow(windowScene: windowScene)
    window.rootViewController = rootVC
    self.window = window
    window.makeKeyAndVisible()
  }
}
  1. AppDelegate 保留 RN 模板中的 moduleName、dependencyProvider、initialProps 和 bundleURL 配置。当前模板的 super.application(_:didFinishLaunchingWithOptions:) 如果仍会创建 window,迁移时不要把它当作 scene 的窗口使用,应以 SceneDelegate 中的 window 为准。若出现重复窗口或根视图空白,删除 AppDelegate 里创建 window 和调用 makeKeyAndVisible() 的逻辑,只保留 RN 工厂初始化。

  2. 清理后重新安装。修改 Info.plist 后要重新构建并安装。模拟器上可以删除旧 App 或执行 Erase Simulator,真机上删除旧 App 后再安装,避免旧的 Info.plist 被缓存。

注意事项

  • 不要只添加 UIApplicationSceneManifest 就结束,必须让 SceneDelegate 设置 window.rootViewController。
  • 项目若自定义了 RCTRootView,或用 RCTReactNativeFactory 手动创建根视图,可以把这段逻辑抽成 makeRootViewController(),再在 SceneDelegate 中调用。
  • 使用 Swift 时,UISceneDelegateClassName 通常写成 $(PRODUCT_MODULE_NAME).SceneDelegate;如果使用 Objective-C,类名要按 target 模块配置调整。
  • 如果后续 RN 版本已经内置 UIScene 模板,优先按官方升级说明迁移,减少长期维护自定义 SceneDelegate 的成本。
  • 以上迁移不会改动 JS 代码,也不需要关闭 New Architecture。

备注:内容仅供参考。