<tfoot id='rPl6a'></tfoot>
    <i id='rPl6a'><tr id='rPl6a'><dt id='rPl6a'><q id='rPl6a'><span id='rPl6a'><b id='rPl6a'><form id='rPl6a'><ins id='rPl6a'></ins><ul id='rPl6a'></ul><sub id='rPl6a'></sub></form><legend id='rPl6a'></legend><bdo id='rPl6a'><pre id='rPl6a'><center id='rPl6a'></center></pre></bdo></b><th id='rPl6a'></th></span></q></dt></tr></i><div id='rPl6a'><tfoot id='rPl6a'></tfoot><dl id='rPl6a'><fieldset id='rPl6a'></fieldset></dl></div>
  1. <legend id='rPl6a'><style id='rPl6a'><dir id='rPl6a'><q id='rPl6a'></q></dir></style></legend>

    <small id='rPl6a'></small><noframes id='rPl6a'>

      <bdo id='rPl6a'></bdo><ul id='rPl6a'></ul>

      从 UIWebView 迁移到 WKWebView

      时间:2023-10-23

      <small id='DxTiP'></small><noframes id='DxTiP'>

        <bdo id='DxTiP'></bdo><ul id='DxTiP'></ul>
            <tfoot id='DxTiP'></tfoot>
            <i id='DxTiP'><tr id='DxTiP'><dt id='DxTiP'><q id='DxTiP'><span id='DxTiP'><b id='DxTiP'><form id='DxTiP'><ins id='DxTiP'></ins><ul id='DxTiP'></ul><sub id='DxTiP'></sub></form><legend id='DxTiP'></legend><bdo id='DxTiP'><pre id='DxTiP'><center id='DxTiP'></center></pre></bdo></b><th id='DxTiP'></th></span></q></dt></tr></i><div id='DxTiP'><tfoot id='DxTiP'></tfoot><dl id='DxTiP'><fieldset id='DxTiP'></fieldset></dl></div>

              <tbody id='DxTiP'></tbody>

            <legend id='DxTiP'><style id='DxTiP'><dir id='DxTiP'><q id='DxTiP'></q></dir></style></legend>

              1. 本文介绍了从 UIWebView 迁移到 WKWebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在我的应用程序中,我正在从 UIWebView 迁移到 WKWebView ,如何为 WKWebView 重写这些函数?

                in my app I'm migrating from UIWebView to WKWebView , how can I rewrite these function for WKWebView?

                    func webViewDidStartLoad(webView: UIWebView){}
                    func webViewDidFinishLoad(webView: UIWebView){}
                

                    func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
                        print("webview asking for permission to start loading")
                        if navigationType == .LinkActivated && !(request.URL?.absoluteString.hasPrefix("http://www.myWebSite.com/exemlpe"))!{
                            UIApplication.sharedApplication().openURL(request.URL!)
                            print(request.URL?.absoluteString)
                            return false
                        }
                        print(request.URL?.absoluteString)
                        lastUrl = (request.URL?.absoluteString)!
                
                        return true
                    }
                
                
                    func webView(webView: UIWebView, didFailLoadWithError error: NSError?) {
                        print("webview did fail load with error: (error)")
                        let testHTML = NSBundle.mainBundle().pathForResource("back-error-bottom", ofType: "jpg")
                        let baseUrl = NSURL(fileURLWithPath: testHTML!)
                
                        let htmlString:String! = "myErrorinHTML"
                        self.webView.loadHTMLString(htmlString, baseURL: baseUrl)
                    }
                

                推荐答案

                UIWebView =>WKWebView 等效

                UIWebViewDelegate => WKNavigationDelegate
                
                delegate => navigationDelegate
                didFailLoadWithError => didFailNavigation
                webViewDidFinishLoad => didFinishNavigation
                webViewDidStartLoad => didStartProvisionalNavigation
                shouldStartLoadWithRequest => decidePolicyForNavigationAction
                

                关于shouldStartLoadWithRequest可以这样写:

                func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
                    print("webView:(webView) decidePolicyForNavigationAction:(navigationAction) decisionHandler:(decisionHandler)")
                    
                    switch navigationAction.navigationType {
                        case .linkActivated:
                        if navigationAction.targetFrame == nil {
                            self.webView?.loadRequest(navigationAction.request)
                        }
                        if let url = navigationAction.request.url, !url.absoluteString.hasPrefix("http://www.myWebSite.com/example") {
                            UIApplication.shared.open(url)
                            print(url.absoluteString)
                            decisionHandler(.cancel)
                        return
                        }
                        default:
                            break
                    }
                    
                    if let url = navigationAction.request.url {
                        print(url.absoluteString)
                    }
                    decisionHandler(.allow)
                }
                

                对于didFailLoadWithError:

                func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
                    print("webView:(webView) didFailNavigation:(navigation) withError:(error)")
                    let testHTML = Bundle.main.path(forResource: "back-error-bottom", ofType: "jpg")
                    let baseUrl = URL(fileURLWithPath: testHTML!)
                
                    let htmlString = "myErrorInHTML"
                    self.webView.loadHTMLString(htmlString, baseURL: baseUrl)
                }
                

                这篇关于从 UIWebView 迁移到 WKWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在 UIWebView 中点击文本框时没有出现键盘 下一篇:如何在 UIWebView 中增加字体大小

                相关文章

                  <bdo id='WdTiU'></bdo><ul id='WdTiU'></ul>
                <tfoot id='WdTiU'></tfoot>

              2. <legend id='WdTiU'><style id='WdTiU'><dir id='WdTiU'><q id='WdTiU'></q></dir></style></legend>
                <i id='WdTiU'><tr id='WdTiU'><dt id='WdTiU'><q id='WdTiU'><span id='WdTiU'><b id='WdTiU'><form id='WdTiU'><ins id='WdTiU'></ins><ul id='WdTiU'></ul><sub id='WdTiU'></sub></form><legend id='WdTiU'></legend><bdo id='WdTiU'><pre id='WdTiU'><center id='WdTiU'></center></pre></bdo></b><th id='WdTiU'></th></span></q></dt></tr></i><div id='WdTiU'><tfoot id='WdTiU'></tfoot><dl id='WdTiU'><fieldset id='WdTiU'></fieldset></dl></div>

                1. <small id='WdTiU'></small><noframes id='WdTiU'>