I am trying to use App Delegate to open a view controller depending on what quick action was selected, but I want to keep the tab Bar Controller a the bottom. My code so far is:

    func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
    let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
    let tabBarController = storyboard.instantiateViewController(withIdentifier: "TabBar") as! UITabBarController

    let CLLViewC = storyboard.instantiateViewController(withIdentifier: "CLL")
    let OLLViewC = storyboard.instantiateViewController(withIdentifier: "OLLStoryboard")
    let PLLViewC = storyboard.instantiateViewController(withIdentifier: "PLL")

    let desiredVC = storyboard.instantiateViewController(withIdentifier: "OLLStoryboard")

    tabBarController.viewControllers = [CLLViewC, OLLViewC, PLLViewC]
    if shortcutItem.type == "com.LukeB.Cubing-practice.OLL" {
        OLLViewC.present(desiredVC, animated: true, completion: nil)

This doesn't work, and I get the error Attempt to present <Cubing_practice.OLLViewController: 0x105803810> on <Cubing_practice.OLLViewController: 0x103f03c50> whose view is not in the window hierarchy! The if statement is accessed though as the console does say present, but the ViewController that opens when I tap the quick action is the default, as if I had just opened the app normally.

What do I need to do to fix this?

0 Answers