title: Triggering a specific action when the app enters foreground from a local notification in iOS? (using swift)
body: <p>I am building an iOS app using the new language Swift. Now it is an HTML5 app, that displays HTML content using the UIWebView. The app has local notifications, and what i want to do is trigger a specific javascript method in the UIWebView when the app enters foreground by clicking (touching) the local notification. </p>
  
  <p>I have had a look at this <a href="https://stackoverflow.com/questions/24638376/get-instance-of-viewcontroller-from-appdelegate-in-swift">question</a>, but it does not seem to solve my problem. I have also come across this <a href="https://stackoverflow.com/questions/23009348/ios-how-can-i-tell-if-a-local-notification-caused-my-app-to-enter-foreground">question</a> which tells me about using UIApplicationState, which is good as that would help me know the the app enters foreground from a notification. But when the app resumes and how do i invoke a method in the viewController of the view that gets displayed when the app resumes?</p>
  
  <p>What i would like to do is get an instance of my ViewController and set a property in it to true. Something as follows</p>
  
  <pre><code>class FirstViewController: UIViewController,UIWebViewDelegate { 
    var execute:Bool = false;
    @IBOutlet var tasksView: UIWebView!
  }
  </code></pre>
  
  <p>And in my AppDelegate i have the method </p>
  
  <pre><code>func applicationWillEnterForeground(application: UIApplication!) {
      let viewController = self.window!.rootViewController;
      let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
  
      var setViewController = mainStoryboard.instantiateViewControllerWithIdentifier("FirstView") as FirstViewController
      setViewController.execute = true;
  
  
  }
  </code></pre>
  
  <p>so what i would like to do is when the app enters foreground again, i want to look at the execute variable and run the method as follows,</p>
  
  <pre><code>if execute{
   tasksView.stringByEvaluatingJavaScriptFromString("document.getElementById('sample').click()");
  }
  </code></pre>
  
  <p>Where should i put the code for the logic to trigger the javascript from the webview? would it be on viewDidLoad method, or one of the webView delegate methods? i have tried to put that code in the viewDidLoad method but the value of the boolean execute is set to its initial value and not the value set in the delegate when the app enters foreground.</p>