title: WKWebView links not working
body: <p>I have build a <code>Swift</code> iOS app with the only purpose to display a website with the help of <strong>WKWebView.</strong></p>
  
  <p>This works fine, but pressing on links (e.g. on an <code>[mailto:]</code> button) doesn't work because it can't open anything!</p>
  
  <p>Does anybody have a solution for this?</p>
  
  <p>I have read a lot about solving this, but I don't know where to start.</p>
  
  <p>Thanks for the help</p>
  
  <p><strong>[UPDATE: ]</strong></p>
  
  <p><em>The code below shows the solution</em></p>
  
  <pre><code>import UIKit
  import WebKit
  
  class ViewController: UIViewController, WKNavigationDelegate {
  
      @IBOutlet var containerView : UIView! = nil
      var webView: WKWebView?
  
      override func loadView() {
          super.loadView()
  
          self.webView = WKWebView()
          self.view = self.webView!
      }
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          webView?.navigationDelegate = self
          let url = NSURL(string:"https://google.de")
          let req = NSURLRequest (URL: url!)
          self.webView!.loadRequest(req)
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
      }
  
      override func prefersStatusBarHidden() -&gt; Bool {
          return true
      }
  
      func webView(webView: WKWebView, decidePolicyForNavigationAction navigationAction: WKNavigationAction, decisionHandler: (WKNavigationActionPolicy) -&gt; Void) {
  
          let url = navigationAction.request.URL?.absoluteString
          let url_elements = url!.componentsSeparatedByString(":")
  
          switch url_elements[0] {
          case "mailto":
              openCustomApp("mailto://", additional_info: url_elements[1])
              decisionHandler(.Cancel)
  
          default:
  
          }
  
          decisionHandler(.Allow)
      }
  
      func openCustomApp(urlScheme:String, additional_info:String){
  
          if let requestUrl:NSURL = NSURL(string:"\(urlScheme)"+"\(additional_info)") {
              let application:UIApplication = UIApplication.sharedApplication()
              if application.canOpenURL(requestUrl) {
                  application.openURL(requestUrl)
              }
          }
      }
  }
  </code></pre>