Ios Swift-应如何覆盖EURLLOADING

Ios Swift-应如何覆盖EURLLOADING,ios,swift,Ios,Swift,我正试图弄清楚如何在IOS版的Swift中覆盖EurlLoading(Android)。我想从webview中捕获URL,而不是加载该URL。斯威夫特能做到这一点吗?它将如何实施?查看 func webView(UIWebView, shouldStartLoadWith: URLRequest, navigationType: UIWebViewNavigationType) 在UIWebViewDelegate()中 将视图控制器设置为web视图的委托,并在上述方法中返回false,以停止

我正试图弄清楚如何在IOS版的Swift中覆盖EurlLoading(Android)。我想从webview中捕获URL,而不是加载该URL。斯威夫特能做到这一点吗?它将如何实施?

查看

func webView(UIWebView, shouldStartLoadWith: URLRequest, navigationType: UIWebViewNavigationType)
在UIWebViewDelegate()中

将视图控制器设置为web视图的委托,并在上述方法中返回
false
,以停止在web视图中加载url

例如:

class MyWebViewController: UIViewController, UIWebViewDelegate {
    func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        if request.url?.absoluteString.contains("dontLoadMe") {
            return false
        }
        return true
    }
}
退房

func webView(UIWebView, shouldStartLoadWith: URLRequest, navigationType: UIWebViewNavigationType)
在UIWebViewDelegate()中

将视图控制器设置为web视图的委托,并在上述方法中返回
false
,以停止在web视图中加载url

例如:

class MyWebViewController: UIViewController, UIWebViewDelegate {
    func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        if request.url?.absoluteString.contains("dontLoadMe") {
            return false
        }
        return true
    }
}

如果您使用的是webview,则使用webview委托方法
shouldStartLoadWithRequest
返回false,表示未在webview中加载URL。例如

func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {

    if request.url?.absoluteString == "https://www.google.com" {
      return false
    }
    return true
}

如果您使用的是webview,则使用webview委托方法
shouldStartLoadWithRequest
返回false,表示未在webview中加载URL。例如

func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {

    if request.url?.absoluteString == "https://www.google.com" {
      return false
    }
    return true
}