Search code examples
iosbackgroundviewdidloadviewdidappear

Why the controller's class method aren't get called when the app become active from background?


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?


Solution

  • 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.