[英]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.我不知道我的错误在哪里。
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,那么您必须为您的项目添加一些更改。
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
...
}
SceneDelegate
method. 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>) {
...
}
UIWindow
object in 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
}
...
}
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.