在AppDelegate中为一个不是第一个

时间:2016-01-13 13:38:07

标签: ios xcode uinavigationcontroller storyboard appdelegate

我正在我的应用中配置Handoff。对于以这种方式构建的应用程序

  

(Entry Point) - > UINavigationController - >   InterestedViewController

这就够了:

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
        if let win = self.window {
            let navController = win.rootViewController as! UINavigationController
            let viewController = navController.topViewController as! myViewController

            viewController.restoreUserActivityState(userActivity)
    }
    return true
}

当使用Handooff启动应用程序时,此方法在AppDelegate中运行,并在“myViewController”中启动方法func restoreUserActivityState(activity: NSUserActivity),一切正常。

麻烦的是我的应用程序是以另一种方式构建的:

  

(Entry Point) - > Another ViewController with animated logo - > UINavigationController - > InterestedViewController

所以前面的代码不起作用。我无法理解如何调整代码...

1 个答案:

答案 0 :(得分:0)

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {   // Handoff

    if let win = window {
        let presentationController = win.rootViewController as! PresentationController
        let navController = presentationController.presentedViewController as! UINavigationController
        let viewController = navController.topViewController as! myViewController

        viewController.restoreUserActivityState(userActivity)
    }

    return true
}