title: Call ViewController Method from AppDelegate after URL Scheme OpenURL
body: <p>I am trying to call a function <code>LoadWebpage</code> in ViewController.m from AppDelegate.m.</p>
  
  <p>I have enabled my app with a URL Scheme such that "urlscheme://?querystring" links in Safari open my app.  I am capturing the url scheme in AppDelegate (I can tell by logging that this is working) and would like to fill a global variable with the querystring and then call my <code>LoadWebPage</code> method so that the view controller can use the global variable and open the requested website in a WebView control.</p>
  
  <p>I am following <a href="https://dev.twitter.com/cards/mobile/deep-linking" rel="nofollow">this tutorial</a>.</p>
  
  <p>This is is AppDelegate.m:</p>
  
  <pre><code>- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
      NSLog(@"Calling Application Bundle ID: %@", sourceApplication);
      NSLog(@"URL scheme:%@", [url scheme]);
      NSLog(@"URL query:%@", [url query]);
      URLString = (NSString *)[url query]; //extern variable
  
      [self.ViewController loadWebpage];
      return YES;
  
  }
  </code></pre>
  
  <p>And in ViewController.m:</p>
  
  <pre><code>- (void)LoadWebpage{
  
      NSString *strURL=URLString;  //more logic will be required to get the appropriate url from the query string.
      NSURL *url = [NSURL URLWithString:strURL];
      NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
      [self.webview loadRequest:urlRequest];
  
  }
  </code></pre>
  
  <p>But the line <code>[self.ViewController loadWebpage];</code> has an error "Property 'ViewController' not found on object of type 'AppDelegate'".</p>
  
  <p>I'm guessing I need to synthesize a reference to the open viewcontroller, but I can't find info on how to do this.  Is this the best way to handle this?</p>
  
  <p>Edit: Based on Yan's comment below, I tried to add</p>
  
  <pre><code>ViewController* mainController = (ViewController*)  self.window.rootViewController;
  [mainController LoadWebpage];
  </code></pre>
  
  <p>Instead of <code>[self.ViewController loadWebpage];</code> but it just ends debugging with lldb?</p>