简体   繁体   English

运行 iOS 应用程序时出现黑屏

[英]black screen when I run my iOS application

I'm trying to do a new iOS app in Xcode.我正在尝试在 Xcode 中做一个新的 iOS 应用程序。 I made a main storyboard and I added a label on my ViewController.我制作了一个主要的 storyboard 并在我的 ViewController 上添加了一个 label。 When I run my application, first second it show the label and then become the screen black without any errors.当我运行我的应用程序时,第一秒钟它显示 label 然后变成黑屏,没有任何错误。

I'm working on Xcode 11 (Swift 5) and this message appears on output:我正在研究 Xcode 11 (Swift 5),这条消息出现在 output 上:

[SceneConfiguration] Info.plist configuration "Default Configuration" for UIWindowSceneSessionRoleApplication contained UISceneDelegateClassName key, but could not load class with name "gina.SceneDelegate" [SceneConfiguration] UIWindowSceneSessionRoleApplication 的 Info.plist 配置“默认配置”包含 UISceneDelegateClassName 键,但无法加载名称为“gina.SceneDelegate”的 class

I don't know where my mistake is.我不知道我的错误在哪里。

运行时黑屏

iOS 13 & above iOS 13及以上

Only if target is 13 or greater.仅当目标为 13 或更大时。

SceneDelegate is not supported before iOS 13 .SceneDelegate 13之前不支持 SceneDelegate。 If you want to use SceneDelegate and also want to support iOS prior to iOS 13 then you a have to add some changes to your project.如果您想使用SceneDelegate并且还想在 iOS 13 之前支持 iOS,那么您必须为您的项目添加一些更改。

  1. Add availability attribute to the whole class in SceneDelegate.swift file.SceneDelegate.swift文件中为整个 class 添加可用性属性。
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
   ...
}
  1. AppDelegate.swift file has two new SceneDelegate method. AppDelegate.swift文件有两个新的SceneDelegate方法。 Add availability attribute to them as well.也为它们添加可用性属性。
@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>) {
  ...
}
  1. Lastly, add UIWindow object in AppDelegate.swift .最后,在AppDelegate.swift中添加UIWindow object 。
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 and earlier iOS 12 及更早版本

AppDelegate needs a UIWindow property. AppDelegate需要一个UIWindow属性。 iOS 13 uses SceneDelegate in new projects. iOS 13在新项目中使用SceneDelegate Specify the UIWindow object and remove the SceneDelegate.swift file.指定UIWindow object 并删除SceneDelegate.swift文件。

If you have removed the SceneDelegate from project, then you must remove the Application Scene Manifest dictionary from Info.plist .如果您已经从项目中删除了SceneDelegate ,那么您必须从Info.plist 中删除Application Scene Manifest字典。

信息列表

You need to initialize the window like this:您需要像这样初始化 window:

let window = UIWindow(windowScene: scene as! UIWindowScene)

and add these in info.plist:并将这些添加到 info.plist 中:

<key>UIApplicationSceneManifest</key>
    <dict>
        <key>UIApplicationSupportsMultipleScenes</key>
        <true/>
        <key>UISceneConfigurations</key>
        <dict>
            <key>UIWindowSceneSessionRoleApplication</key>
            <array>
                <dict>
                    <key>UILaunchStoryboardName</key>
                    <string>LaunchScreen</string>
                    <key>UISceneConfigurationName</key>
                    <string>Default Configuration</string>
                    <key>UISceneDelegateClassName</key>
                    <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
                </dict>
            </array>
        </dict>
    </dict>

That's all you need to do.这就是你需要做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS:运行我的应用程序时出现黑屏 - iOS : Black screen appears when run my app 当我打开 iOS 应用程序时,屏幕变黑。 为什么? - When I opened my iOS app, the screen turns black. Why? 当我加载我的应用程序时,IOS 模拟器是黑色的 - IOS simulator is black when I load my app 在iOS 7中退出UIDocumentInteractionController PDF时出现黑屏 - Black screen when exiting PDF of UIDocumentInteractionController in iOS 7 (iOS)自定义初始化UIViewController时出现黑屏 - (iOS) Black screen when custom initializing UIViewController iOS:加载应用程序时出现随机黑屏 - iOS: Random black screen when loading the app 在 iOS 15.4 上使用 ARGeoTrackingConfiguration 时黑屏? - Black screen when using ARGeoTrackingConfiguration on iOS 15.4? 当我在ios模拟器中运行应用时,我的应用被卡在显示版权内容的白屏上 - My app gets stuck on a white screen that says copyright stuff when i run it in a ios simulator 在我的iOS应用程序中,进入该特定屏幕时,我需要显示默认的5个用户 - In my application in iOS i need to show the default 5 users when enters in to that particular screen Xcode 将在设备上运行 Unity 应用程序,但是当我运行构建的应用程序时,会出现黑屏 - Xcode will run the Unity app on device, but when I run the built app, the black screen will appear
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM