iOS swift 3.0 UIWebView&WKWe

作者: 高扬先生 | 来源:发表于2017-03-10 11:12 被阅读358次

    swift 3.0 UIWebView

    // swift 3.0 UIWebView
    func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
            
            BaiduMobStat.default().webviewStartLoad(with: request)
            
            let requestURLScheme = request.url?.scheme
    
            if (requestURLScheme == "http" || requestURLScheme == "http" || requestURLScheme == "http") && navigationType == .linkClicked {
                
                return !UIApplication.shared.openURL(request.url!)
    
            }
            
            return true
        }
    

    swift 3.0 WKWebView

    // swift 3.0 WKWebView
        func webView(webView: WKWebView, decidePolicyForNavigationAction navigationAction: WKNavigationAction, decisionHandler: (WKNavigationActionPolicy) -> Void) {
            
            let requestURLScheme = navigationAction.request.url?.scheme
            
            if (requestURLScheme == "http" || requestURLScheme == "http" || requestURLScheme == "http") && navigationAction.navigationType == .linkActivated {
                
                if UIApplication.shared.openURL(navigationAction.request.url!) {
                    decisionHandler(.cancel)
                }else{
                    decisionHandler(.allow)
                }
                
            }
            
            decisionHandler(.allow)
        }
    

    相关文章

      网友评论

        本文标题:iOS swift 3.0 UIWebView&WKWe

        本文链接:https://www.haomeiwen.com/subject/jlyngttx.html