Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The view controller doesn't load its view until something asks it for its view. At launch time, that normally happens after <code>application:didFinishLaunchingWithOptions:</code> returns.</p> <p>You might wonder why. The answer is that you might instantiate several view controllers at launch time, some of which are hidden. For example, if your window's root view controller is a <code>UINavigationController</code>, you might load the navigation controller with a stack of view controllers (the stack that the user had pushed the last time the app ran). Only the top view controller of this stack is visible, so there's no need to load the views of the other view controllers. The system waits until <code>application:didFinishLaunchingWithOptions:</code> returns before loading any views so that only the necessary views will be loaded.</p> <p>So one way to work around your problem would simply be to ask the view controller for its view, thus forcing it to load. If your view controller is the window's root view controller, you can do it this way:</p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UILocalNotification *localNotification = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey]; if (localNotification) { [[self.window rootViewController] view]; [[NSNotificationCenter defaultCenter] postNotificationName:@"Resume" object:self userInfo:localNotification.userInfo]; AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); } return YES; } </code></pre> <p>A different workaround would be to start observing the notification in your view controller's <code>initWithCoder:</code> method:</p> <pre><code>- (id)initWithCoder:(NSCoder *)aDecoder { if (self = [super initWithCoder:aDecoder]) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resumeByNotification:) name:@"Resume" object:nil]; } return self; } </code></pre> <p>This is called when the view controller is instantiated from the MainStoryboard, which happens before the <code>application:didFinishLaunchingWithOptions:</code> message.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload