ios - 当我运行 iOS 应用程序时黑屏

标签 ios

我正在尝试在 Xcode 中制作一个新的 iOS 应用程序。我制作了一个主 Storyboard,并在 ViewController 上添加了一个标签。当我运行我的应用程序时,第一秒它显示标签,然后黑屏,没有任何错误。

我正在使用 Xcode 11 (Swift 5),此消息出现在输出中:

[SceneConfiguration] Info.plist configuration "Default Configuration" for UIWindowSceneSessionRoleApplication contained UISceneDelegateClassName key, but could not load class with name "gina.SceneDelegate"

我不知道我的错误在哪里。

black screen when running

最佳答案

iOS 13 及更高版本

Only if target is 13 or greater.

SceneDelegateiOS 13 之前不受支持。如果您想使用 SceneDelegate 并且还想支持 iOS 13 之前的 iOS,那么您必须向您的项目添加一些更改。

  1. 将可用性属性添加到 SceneDelegate.swift 文件中的整个类。
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
   ...
}
  • AppDelegate.swift 文件有两个新的 SceneDelegate 方法。还为它们添加可用性属性。
  • @available(iOS 13.0, *)
    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
      ...
    }
    
    @available(iOS 13.0, *)
    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
      ...
    }
    
  • 最后,在 AppDelegate.swift 中添加 UIWindow 对象。
  • class AppDelegate: UIResponder, UIApplicationDelegate {
    
        //Add this line
        var window: UIWindow?
    
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            // Override point for customization after application launch.
            return true
        }
    
        ...
    }
    
    <小时/>

    iOS 12 及更早版本

    AppDelegate 需要 UIWindow 属性。 iOS 13 在新项目中使用 SceneDelegate。指定 UIWindow 对象并删除 SceneDelegate.swift 文件。

    如果您已从项目中删除了 SceneDelegate,则必须从 Info.plist< 中删除Application Scene Manifest 字典/strong>.

    Info.plist

    关于ios - 当我运行 iOS 应用程序时黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58209675/

    相关文章:

    android - Unity 游戏引擎上的语音识别

    ios - 如何正确实现嵌套 block ? ios

    ios - 为什么我的 CBPeripheralManager 有广告但无法被发现?

    ios - [managedObjectContext reset] 时核心数据崩溃;

    ios - 在后台获取Core Data对象和tableView.reloadData()

    iphone - 在应用内购买后更改应用名称

    javascript - iOS 11 navigator.getUserMedia 在 Chrome 中未定义

    ios - 使用 Button 生成 FlexBox 布局

    ios - prepareForSegue 中出现“从不正确的线程访问的 Realm ”错误; swift

    ios - 向 CorePlot 切片添加图例