Webview does not capture gestures

Asked

Viewed 45 times

0

Wkwebview loads the link but I can’t perform any action on the site

Viewcontroller

import UIKit
import WebKit

class promoVC: UIViewController{

@IBOutlet weak var webView: WKWebView!

override func viewDidLoad() {
    super.viewDidLoad()


    webView.navigationDelegate = self
    webView.loadURL(strURL: "https://rh.mazza.tech/web/guest/webuser");
}

}
 extension promoVC : WKNavigationDelegate{

func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
    print(error.localizedDescription)
}

func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
    print("Webview is loading")
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
    print("")
}
}
  • Does your code compile? Wkwebview does not have a method called loadURL(String). The method is load(Urlrequest) https://developer.apple.com/documentation/webkit/wkwebview/1414954-load

  • Compile, it opens the site, but I can’t use the site

1 answer

0

The way of webView loadURL does not compile, You need to use the method load

import UIKit
import WebKit

class ViewController: UIViewController {

@IBOutlet weak var webView: WKWebView!

override func viewDidLoad() {
    super.viewDidLoad()

    if let url = URL(string: "https://rh.mazza.tech/web/guest/webuser") {
        webView.load(URLRequest(url: url))
        webView.allowsBackForwardNavigationGestures = true
        webView.navigationDelegate = self
    }
}
}

extension ViewController: WKNavigationDelegate {
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
     print(error.localizedDescription)
}

func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
     print("Webview is loading")
}

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
    print("")
}
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.