title: iOS black screen when bringing app to foreground after some time in background
body: <p>I'm trying to remove all storyboards from our iOS app as they are a huge mess when working in a team with Git.</p>
  
  <p>I'm now setting the initial ViewController in AppDelegate's <code>application(_:didFinishLaunchingWithOptions:)</code> method:</p>
  
  <pre><code>func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -&gt; Bool {
  
      window = UIWindow(frame: UIScreen.main.bounds)
      let launchViewController = LaunchView()
      window!.rootViewController = launchViewController
      window!.makeKeyAndVisible()
  
      [...]
  
      return true
  }
  </code></pre>
  
  <p>LaunchView is a simple view controller responsible of routing the user to login or main screen depending if he/she is logged in.</p>
  
  <p>Before this, LaunchView was set as initial in <code>Main.storyboard</code>.</p>
  
  <p>I already removed these lines from <code>Info.plist</code> file:</p>
  
  <pre><code>&lt;key&gt;UIMainStoryboardFile&lt;/key&gt;
  &lt;string&gt;Main&lt;/string&gt;
  </code></pre>
  
  <p>Everything is working fine, except when we leave the app in background for a couple hours without force-quitting it (I'm not sure how much time is needed to reproduce this) and then bring the app back to foreground, an all-black screen is shown, as if the root controller disappeared. And we have to kill the app and reopen it again in order to use it.</p>
  
  <p>This is driving me crazy because it is really hard to reproduce, since if you leave the app in background only for a few minutes it works fine.
  I'm suspecting it has something to do with the app suspended state, but I'm not really sure.</p>
  
  <p>Do you know where the problem might be?</p>
  
  <p>Thank you!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Maybe this has something to do with the problem:
  On the LaunchView, I'm sending the user to the main screen (if he is logged in) with the following code:</p>
  
  <pre><code>guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
  
  let rootVC = UIStoryboard.main.rootViewController
  if let snapshot = appDelegate.window?.snapshotView(afterScreenUpdates: true) {
  
      rootVC.view.addSubview(snapshot);
      appDelegate.window?.rootViewController = rootVC
  
      UIView.transition(with: snapshot, duration: 0.4, options: .transitionCrossDissolve, animations: {
          snapshot.layer.opacity = 0;
      }, completion: { (status) in
          snapshot.removeFromSuperview()
      })
  }
  else {
      appDelegate.window?.rootViewController = rootVC
  }
  </code></pre>
  
  <p>Is it possible that iOS is removing rootViewController at some point?</p>