I'm trying to remove all storyboards from our iOS app as they are a huge mess when working in a team with Git.
I'm now setting the initial ViewController in AppDelegate's application(_:didFinishLaunchingWithOptions:)
method:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
let launchViewController = LaunchView()
window!.rootViewController = launchViewController
window!.makeKeyAndVisible()
[...]
return true
}
LaunchView is a simple view controller responsible of routing the user to login or main screen depending if he/she is logged in.
Before this, LaunchView was set as initial in Main.storyboard
.
I already removed these lines from Info.plist
file:
<key>UIMainStoryboardFile</key>
<string>Main</string>
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.
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.
Do you know where the problem might be?
Thank you!
EDIT
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:
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
}
Is it possible that iOS is removing rootViewController at some point?
Launch.storyboard
. This is selected as Launch Screen File (UILaunchStoryboardName
key in Info.plist). – JoseMain.storyboard
as I have the main view controller in there and didn't refactor it yet. – JoseapplicationDidEnterBackground
I'm posting an `NSNotification' to default notification center, and using it in a couple observers to stop some processes running in background threads. Nothing UI-related. – JosedefinesPresentationContext = true
, but I will and let you know, thanks! – JoseMain.storyboard
as the Main Interface, I'm only using it as a regular storyboard. – JoseapplicationDidBecomeActive
andapplicationDidEnterBackground
. Both methods are sending an NSNotification to the Default center to inform interested observers, and these observers don't execute any UI-related code. I don't think this part has nothing to do with the problem, because it is doing exactly the same than before (when the problem didn't exist) – JosedefinesPresentationContext = true
onviewDidLoad()
didn't work :( – Jose