I need to implement the following check in my AppDelegate
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// If logged in, jump to tabs
let isUserLoggedIn = UserDefaults.standard.bool(forKey: "isUserLoggedIn")
print(isUserLoggedIn)
if isUserLoggedIn {
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let tabBarController = storyboard.instantiateViewController(withIdentifier: "tabs") as! TabBarController
self.window?.rootViewController = tabBarController
self.window?.makeKeyAndVisible()
}
return true
}
The problem is I'm using Xcode 11 which has the new AppDelegate
/ SceneDelegate
setup. Because of this, the UIWindow
is nil
, so the new rootViewController
is not set. I know that in iOS 13 the window is accessed in the SceneDelegate
, but this project's target is iOS 12.4. The SceneDelegate
has been preceeded by @available(iOS 13.0, *)
.
How can I access UIWindow from the appDelegate or how can I make the above code work?
I'm working with Xcode 11 and Swift 4.2.