title: Migrating UIWebView delegate to WKWebView delegate method
body: <p>I am working on migrating UIWebView to WKWebView. I have changed all the Delegate methods. I need WKWebView delegate methods equal to below UIWebView delegate method. The app is working fine. but login session is not retaining</p>
  
  <pre><code>UIWebView:
  
      extension WebViewController: UIWebViewDelegate {
  
      func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -&gt; Bool {
  
      guard let url = request.url else {
         return true
      }
  
      guard !url.absoluteString.contains("data:application/pdf") else {
          navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.action,
                                                              target: self,
                                                              action: #selector(share(sender:)))
          return true
      }
  
      guard url.pathExtension != "pdf" else {
          let safariVC = SFSafariViewController(url: url)
          safariVC.modalPresentationStyle = .popover
          present(safariVC, animated: true, completion: nil)
          return false
      }
  
      guard url.isLogin() == false else {
          AppDelegate.navigationController.signOut(.sessionOnly)
          return false
      }
  
      guard let mobileSite = url.asMobileSite() else {
          return true
      }
  
      let mobileRedirect = URLRequest(url: mobileSite)
      webView.loadRequest(mobileRedirect)
      return false
  
  }
  
  func webViewDidStartLoad(_ webView: UIWebView) {
      numberOfDidStartLoads += 1
  }
  
  func webViewDidFinishLoad(_ webView: UIWebView) {
      numberOfDidStartLoads -= 1
  }
  
  func webView(_ webView: UIWebView, didFailLoadWithError error: Error) {
      numberOfDidStartLoads -= 1
  }
  }
  </code></pre>
  
  <p>And i tried below code and getting session expire.</p>
  
  <pre><code>extension WebViewController: UIWebViewDelegate {
  
      func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (_: WKNavigationActionPolicy) -&gt; Void) {
  
      guard let url = navigationAction.request.url else {
          decisionHandler(.allow)
          return
      }
  
      guard !url.absoluteString.contains("data:application/pdf") else {
          navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.action,
                                                              target: self,
                                                              action: #selector(share(sender:)))
          decisionHandler(.allow)
          return
      }
  
      guard url.pathExtension != "pdf" else {
          let safariVC = SFSafariViewController(url: url)
          safariVC.modalPresentationStyle = .popover
          present(safariVC, animated: true, completion: nil)
          decisionHandler(.cancel)
          return
      }
  
      guard url.isLogin() == false else {
          AppDelegate.navigationController.signOut(.sessionOnly)
          decisionHandler(.cancel)
          return
      }
  
      guard let mobileSite = url.asMobileSite() else {
          decisionHandler(.allow)
          return
      }
  
      let mobileRedirect = URLRequest(url: mobileSite)
      webView.load(mobileRedirect)
      decisionHandler(.cancel)
      return
  
      decisionHandler(.allow)
  
  }
  
      func webViewDidStartLoad(_ webView: UIWebView) {
          numberOfDidStartLoads += 1
      }
  
      func webViewDidFinishLoad(_ webView: UIWebView) {
          numberOfDidStartLoads -= 1
      }
  
      func webView(_ webView: UIWebView, didFailLoadWithError error: Error) {
          numberOfDidStartLoads -= 1
      }
  }
  </code></pre>
  
  <p>Please help me to resolve this issue. I have made some mistake in changing code from UIWebView to WKWebView.</p>