【问题标题】:How to access the rootViewController when using BlackBerry Dynamics SDK使用 BlackBerry Dynamics SDK 时如何访问 rootViewController
【发布时间】:2019-10-09 09:40:44
【问题描述】:

我正在开发一个带有多个视图控制器的 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!

注意:UIViewController: 0x7ffc70714c40 不是 HomeController! ('HomeController' 在 storyboard 中被标记为:Is Initial View Controller)

在调试模式下(没有 BlackBerry SDK)应用运行良好。

我的 AppDelegate::didFinishLaunchingWithOptions...:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
       
    // Override point for customization after application launch.
    
#if !DEBUG
    XXXGDiOSDelegate.sharedInstance.appDelegate = self
    GDiOS.sharedInstance().authorize(XXXGDiOSDelegate.sharedInstance)
#else
    let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "HomeController") as? HomeController
    window = UIWindow()
    window?.makeKeyAndVisible()
    window?.rootViewController = controller
#endif
    return true
}

我的问题: 使用 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
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
       
    // Override point for customization after application launch.
    
#if !DEBUG
    XXXGDiOSDelegate.sharedInstance.appDelegate = self
    GDiOS.sharedInstance().authorize(XXXGDiOSDelegate.sharedInstance)
#endif

    let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "HomeController") as? HomeController
    window = UIWindow()
    window?.makeKeyAndVisible()
    window?.rootViewController = controller

    return true
}

【问题讨论】:

    标签: swift blackberry ios13 rootviewcontroller


    【解决方案1】:

    我的解决方案...我按照以下说明进行操作(objective-c):

    https://developer.blackberry.com/devzone/files/blackberry-dynamics/ios/_app_user_interface_restrictions.html

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

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

    成员变量:

    var run_once: Bool = false
    

    修改了didAuthorize:

    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
        }
    }
    

    现在应用在发布模式下也可以正常运行了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-01
      • 1970-01-01
      • 2015-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-28
      • 1970-01-01
      相关资源
      最近更新 更多