0

when I share something with my app, it get called by -(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{to get the content shared with it. After that, i need to present Modally a content in the first controller of the app, but if call from the appDelegatethe function [self.library showContent:item];where's library is the main controller on the app, it doesn't called the class method like viewDidLoad or viewDidAppear of the main controller but only the applicationDidBecomeActive from appDelegate, and i can't run apresentModalViewController from the showContent method, because it's view isn't on screen yet.

short version: why when app comes from applicationDidBecomeActive it doesn't call first controller's class method like viewDidAppear ? How con i call in the main controller a presentModalViewController if I didn't know when the main controller is on screen?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Alessio Crestani
  • 1,602
  • 4
  • 17
  • 38

2 Answers2

1

I think that U r mixing up the UIViewController Lifecycle and application lifecycle, this two are different.

Brief tip: take your code from ViewDidAppearout to external method and try to invoke this method somewhere from applicationDidBecomeActive.

For application lifecycle, see this link.

For UIViewController lifecycle see this link.

Hope that could help.

gran33
  • 12,421
  • 9
  • 48
  • 76
  • "Brief tip: take your code from ViewDidAppearout to external method and try to invoke this method somewhere from applicationDidBecomeActive." Ok, but i need to know that when i call this function my controller (the old one) is on screen, to finally create a new modal one on it. – Alessio Crestani Jul 29 '14 at 07:14
  • yeah but if I try to instantiate a presentmodalview on it on Log I see " whose view is not in the window hierarchy!" – Alessio Crestani Jul 29 '14 at 07:34
0

When the application becomes active from the background it opens with the view it has in the front when it was put in the background. To present a view controller when you share something with your app using a url scheme, you have to tell your app to do so in your handle open url method:

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation{
         /* put code to get the data you want to extract
         from the url scheme here */
         // and then load the view
         MyController *v = [[MyController alloc] init]; 
         [self loadThisController:v];//replace with any method you want to use to load this.
}
Nikos M.
  • 13,685
  • 4
  • 47
  • 61
  • I know, but i don't want to replace the old controller with the new one. The new one has to be a modal controller in the old one, so i need to finish load the old one and load in it a presentModalViewController. – Alessio Crestani Jul 29 '14 at 07:03
  • @Nikos M. I think that your answer mislead. When u reload the viewController U deal with some side effect that u not necessarily wants such as network call, I/O and more. – gran33 Jul 29 '14 at 07:05