Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

black screen when I run my iOS application

Tags:

I'm trying to do a new iOS app in Xcode. I made a main storyboard and I added a label on my ViewController. When I run my application, first second it show the label and then become the screen black without any errors.

I'm working on Xcode 11 (Swift 5) and this message appears on output:

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

I don't know where my mistake is.

black screen when running

like image 935
jeena azeez Avatar asked Oct 02 '19 21:10

jeena azeez


People also ask

Why does my Iphone screen go black when I open an app?

If the app freezes up and the screen goes black when trying to load a video or media content, it could be an issue with the internet connection, or internet connection speed. This could also be due to some throttling going on by an ISP itself, or by the media delivery network, or some other related provider.

Why is my app screen black?

app on your Android mobile device, this is likely due to an incompatibility issue with Android System Webview. This issue may occur immediately upon opening the application, when trying to sign in, or when creating a new account.


2 Answers

iOS 13 & above

Only if target is 13 or greater.

SceneDelegate is not supported before iOS 13. 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.

  1. Add availability attribute to the whole class in SceneDelegate.swift file.
@available(iOS 13.0, *) class SceneDelegate: UIResponder, UIWindowSceneDelegate {    ... } 
  1. AppDelegate.swift file has two new SceneDelegate method. 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.
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

AppDelegate needs a UIWindow property. iOS 13 uses SceneDelegate in new projects. Specify the UIWindow object and remove the SceneDelegate.swift file.

If you have removed the SceneDelegate from project, then you must remove the Application Scene Manifest dictionary from Info.plist.

Info.plist

like image 123
Somoy Das Gupta Avatar answered Sep 17 '22 20:09

Somoy Das Gupta


You need to initialize the window like this:

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

and add these in 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.

like image 21
Munzareen Atique Avatar answered Sep 17 '22 20:09

Munzareen Atique