Short Version:
When I exit the App (home button), UIApplicationExitsOnSuspend is set to NO, and open a custom file from Mail into my App, which method of a UIViewController is invoked?
Alternatively, How do I make my AppDelegate to -performSegueWithIdentifier of my rootViewController? Is this code safe?
UIViewController *vc = [self.window.rootViewController.childViewControllers objectAtIndex:0];
[vc performSegueWithIdentifier:@"ChiesaSegue" sender:vc];
More Details:
I have got my App with storyboard “Embedded In” a Navigation Controller with two different UIViewControllers, let’s say FirstVC and SencondVC connected together with proper Segues. I have associated custom file extensions (let’s say .q80) with my App by setting up my info.plist file, and I can see my custom file showing up with my App icon in Mail. All of this works perfectly fine.
I close the App (home button), and go to Mail, and “Open In..” a file, App opens up and I properly handle the incoming URL in AppDelegate‘s
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
Now, I want to be able to load the data of this imported URL in my SecondVC, however every time I “Open In..” a file I get old data back exactly the way I left it when I hit the home button. I don’t know which method of FirstVC or SecondVC is invoked after my URL is processed in application:openURL:sourceApplication:annotation! I am cleaning the old data and setting up the new data in -viewDidLoad, and also -viewWillAppear. Nothing happens!
Let me know if you need code, or other details I might have missed.
It is entirely possible that none of the view controller viewWillLoad/Appear/etc methods will be called when returning from the background. If you need to some behavior in the view controllers based on things in the openURL application delegate method, then you have to trigger it explicitly. You could use a NSNotification for this purpose. Alternatively, if your openURL method is modifying some application model state, you could use key-value observing on your model objects.