At the moment, I have implemented these two methods in my AppDelegate
func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool
and
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool
The first will get called if the user opens my app with a search result from Spotlight and the second one gets called if my app gets opened from Apple Maps (since it's a routing app).
MY QUESTION IS, WHAT IS THE BEST WAY TO GO TO A SPECIFIC UIViewController FROM APPDELEGATE (independent from no matter what view the user is in)?
The reason I ask is because at the moment I'm trying to navigate to it manually depending where the user may be. For example, they may be in a UIViewController that is displayed modally (which then needs to be dismissed) or they may be deep in a UINavigationController, in which the app will then need to call popToRootViewController.
Doing it this way, the code is getting hairy and doesn't seem to work right. It also just doesn't seem right to do it this way either because it is very fragile.
I just was trying to figure out the how to implement the first method you mentioned and found a helpful start from https://www.hackingwithswift.com/read/32/4/how-to-add-core-spotlight-to-index-your-app-content His code is:
I found self.window?.rootViewController as? yourRootViewControllerClass a good springboard for your question.
My code, which was very basic, looks like this:
This works for me but I must give a caveat. My app has only one storyboard with three viewControllers (NavController->tableViewController->ViewController). I am not sure how this logic will work on more complex apps.
Another good reference is: http://www.appcoda.com/core-spotlight-framework/
That viewController has this method: