splitView中的didReceiveRemoteNotification presentViewController

时间:2016-05-24 09:36:59

标签: ios push-notification uisplitviewcontroller presentviewcontroller

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

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以便我可以连接根视图控制器和我的视图之间的所有视图?

希望有人可以帮助我。我一直在努力奋斗好几个小时。提前谢谢!

1 个答案:

答案 0 :(得分:0)

我终于找到了答案!它基于@ StepanGeneralov的回答https://stackoverflow.com/a/21297223/6144027。我在这里发布,因为这可能有一天会帮助别人。

    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。