我当前正在为应用创建webView。我需要做的是,当有人单击webView中的链接时,需要在Safari中打开它。
我正在使用UIWebView在Swift中进行此操作。
在这篇stackoverflow文章中,我发现(UIWebView open links in Safari)已经找到了一些显然对许多人有用的代码,但我不确定该怎么做
答案 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
}