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 think the good place for renavigation is an event
UIApplicationDidBecomeActiveNotification
with subscription in root view controller (whatever you use).When you do your code in
AppDelegate
- just schedule an Action: assemble your parcel with abstract number of properties, data parameters and so on. Store it somewhere (NSUserDefauils - is good place to be, but it may be even SqlCipher instance). And keep rest with hoping to following event.When
UIApplicationDidBecomeActiveNotification
is fired - wake up, catch stored Action parcell, and perform your renavigation according to Action properties.About your modal view controllers. They (exactly - controllers WHO show) should be ready to dismiss all VC's they show modally when renavigation event arrive.