iOS swift 3.0 UIWebView&WKWebView 劫持点击链接事件,在Safari中打开

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&WKWebView 劫持点击链接事件,在Safari中打开)