UIWebView处理链接

时间:2020-04-23 18:13:29

标签: ios swift webview

我当前正在为应用创建webView。我需要做的是,当有人单击webView中的链接时,需要在Safari中打开它。

我正在使用UIWebView在Swift中进行此操作。

在这篇stackoverflow文章中,我发现(UIWebView open links in Safari)已经找到了一些显然对许多人有用的代码,但我不确定该怎么做

1 个答案:

答案 0 :(得分:1)

UIWbView已死,Apple将在2020年12月之后不再接受它。

Deprecated API Usage - Apple will stop accepting submissions of apps that use UIWebView APIs.

仍然要使用UIWebView,可以尝试使用此方法...

func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebView.NavigationType) -> Bool {
            if request.url == request.mainDocumentURL, let url = request.url, UIApplication.shared.canOpenURL(url){
                UIApplication.shared.openURL(url)
                return false
            }
            return true
        }