我还没有看到提到的一项,涉及 Xcode 11 beta 5 (11M382q) 涉及更新您的应用程序的 info.plist 文件。
对于我的场景,我正在采用现有的基于 Swift 和 UIKit 的应用程序并将其完全迁移为 iOS 13 和纯 SwiftUI 应用程序,因此向后兼容性对我来说不是问题。
对 AppDelegate 进行必要的更改后:
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration",
sessionRole: connectingSceneSession.role)
}
并添加一个 SceneDelegate 类:
import UIKit
import SwiftUI
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: HomeList())
self.window = window
window.makeKeyAndVisible()
}
}
}
我遇到了一个问题,我的 SceneDelegate 没有被调用。通过将以下内容添加到我的 info.plist 文件中已解决此问题:
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneClassName</key>
<string></string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneStoryboardFile</key>
<string>LaunchScreen</string>
</dict>
</array>
</dict>
</dict>
还有一个截图可以看到:

要保持同步的主要项目是:
- 委托类名,以便 Xcode 知道在哪里可以找到您的
SceneDelegate
文件
- 配置名称,以便 AppDelegate 中的调用可以加载正确的
UISceneConfiguration
这样做之后,我就可以加载我新创建的 HomeList 视图(一个 SwiftUI 对象)