Swift 使用BlackBerry Dynamics SDK时如何访问rootViewController

Swift 使用BlackBerry Dynamics SDK时如何访问rootViewController,swift,blackberry,ios13,rootviewcontroller,Swift,Blackberry,Ios13,Rootviewcontroller,我正在删除一个带有多个视图控制器的iOS 13应用程序(使用故事板,不带导航控制器,不带启动屏幕)。 对于取消/显示视图控制器,我使用以下代码: @objc func onMenuItemUploadsTap(_ sender: UIView) { self.view.window!.rootViewController?.dismiss(animated: false, completion: { let appDelegate = UIApplication.shar

我正在删除一个带有多个视图控制器的iOS 13应用程序(使用故事板,不带导航控制器,不带启动屏幕)。 对于取消/显示视图控制器,我使用以下代码:

@objc func onMenuItemUploadsTap(_ sender: UIView) {
    self.view.window!.rootViewController?.dismiss(animated: false, completion: {
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        let vc = appDelegate.getViewController(viewController: .Uploads)
        vc.modalPresentationStyle = .fullScreen
        UIApplication.shared.windows.first!.rootViewController!.present(vc, animated: true, completion: nil)
    })
}
实例化viewController后,我将它们保存在AppDelegate中,因为用户可以从viewController跳到viewController 因此,viewController必须保持其状态/值,这就是为什么我使用:

let vc = appDelegate.getViewController(viewController: .Uploads)
好的。。。当我在发布模式下运行应用程序时,只会显示初始的viewController(名为:HomeController),而不是我想显示的“vc”,调试控制台会告诉我:

Attempt to present <XXX.UploadController: 0x7ffc71152400> on <UIViewController: 0x7ffc70714c40> whose view is not in the window hierarchy!
我的问题: 使用BlackBerry SDK时如何访问rootViewController

我正在使用: macOS Mojave 10.14.6,xCode 11.1(11A1027),BlackBerry_Dynamics_SDK_for_iOS_v6.1.0.170

提前谢谢

我试过:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
       
    // Override point for customization after application launch.
    let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "HomeController") as? HomeController
    window = UIWindow()
    window?.makeKeyAndVisible()
    window?.rootViewController = controller

#if !DEBUG
    XXXGDiOSDelegate.sharedInstance.appDelegate = self
    GDiOS.sharedInstance().authorize(XXXGDiOSDelegate.sharedInstance)
#endif
    return true
}


我的解决方案。。。我遵循以下说明(目标c):

(参见此处:实例化应用程序用户界面)

…并在我的AppDelegate中实现了这一点:

成员变量:

var run_once: Bool = false
修改后的授权:

func didAuthorize() -> Void {

    print(#file, #function)

    //I added this if block:
    if !self.run_once {
        self.run_once = true
        let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "HomeController") as? HomeController
        window = UIWindow()
        window?.makeKeyAndVisible()
        window?.rootViewController = controller
        UIApplication.shared.windows.first!.rootViewController = controller
    }
}
现在,该应用程序在发布模式下也可以正常运行

var run_once: Bool = false
func didAuthorize() -> Void {

    print(#file, #function)

    //I added this if block:
    if !self.run_once {
        self.run_once = true
        let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "HomeController") as? HomeController
        window = UIWindow()
        window?.makeKeyAndVisible()
        window?.rootViewController = controller
        UIApplication.shared.windows.first!.rootViewController = controller
    }
}