splitView 中的 didReceiveRemoteNotification presentViewController

didReceiveRemoteNotification presentViewController within splitView

我一直在尝试在推送通知到达时在我的应用程序上打开一个特定的视图,但是这个视图是通过拆分视图的详细视图以模态方式呈现的,我无法做到这一点。

This is my story board

我已经尝试了关于主题的众多答案之一,它只是呈现 EventsViewController,但显然这种方式使 VC 孤立并且不再连接到拆分视图。

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { 
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let navigationController = storyboard.instantiateViewControllerWithIdentifier("NavigationControllerMessages") as! UINavigationController
    let dVC:MessagesViewController = navigationController.topViewController as! MessagesViewController
    dVC.vehicleLicensePlate = "ABC"
    dVC.vehicleName = "My car"
    self.window?.rootViewController?.presentViewController(navigationController, animated: true, completion: {})

}

我也试过呈现实际有效的拆分视图,但我不知道如何爬升层次视图以到达 EventsViewController:

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let destinationViewController = storyboard.instantiateViewControllerWithIdentifier("SplitInStoryboard") as! SplitViewController
    self.window?.rootViewController?.presentViewController(destinationViewController, animated: true, completion:nil)

}

问题是如何呈现 EventsViewController 以便我可以连接根视图控制器和我的视图之间的所有视图?

希望有人能帮助我。我已经为此苦苦挣扎了好几个小时。提前致谢!

终于找到答案了!它基于@StepanGeneralov 的回答 。我 post 把它放在这里是因为有一天这可能会对某人有所帮助。

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let mvc = storyboard.instantiateViewControllerWithIdentifier("MessagesInStoryboard") as! MessagesViewController
    mvc.vehicleName = "My car"
    mvc.vehicleLicensePlate = "ABC"
    let navController = UINavigationController(rootViewController: mvc) // Creating a navigation controller for mvc

    var topRootViewController : UIViewController! = self.window?.rootViewController
    while let vvc = topRootViewController.presentedViewController{
        topRootViewController = vvc

    }
    topRootViewController.presentViewController(navController, animated: true, completion: nil)

顺便说一下,正如@guillaume 指出的那样,我们应该实施 application:didReceiveRemoteNotification:fetchCompletionHandler: 而不仅仅是 didReceiveRemoteNotification。