我有一个URL请求
let url = URL(string: "https://www.google.com/share?referCode=RSJDofpeW")
我们想在WebView中打开此URL,并且此链接也与通用链接相关联。因此,打开此URL将打开已安装的应用程序,但我想在UIWebView中加载页面。因此,我检查了代表,发现它首次称为上述URL,然后下次它将添加方案和AppStore重定向。
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
log.verbose(webView)
log.verbose(request)
log.error(navigationType.rawValue)
if request.url?.scheme == "itms-appss" || request.url?.scheme == "googleApp"{
return false
}
return true
}
因此,为了克服不加载页面在Web视图中的问题,我像上面一样执行了代码,因此当方案为itms-appss
或googleApp
时,它不会加载请求,而是第一次加载正确的URL时,应该加载该页面但这没有打开。
//检查
var isUrlLoaded : Bool = false;
//委托功能
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
//check is the url is loaded for first time or not
if isUrlLoaded != true{
if request.url?.scheme == "itms-appss" || request.url?.scheme == "googleApp"{
return true
}
}
return false
}
func webViewDidFinishLoad(_ webView: UIWebView) {
if webView.request?.url?.scheme == "itms-appss" || webView.request?.url?.scheme == "googleApp"{
// is url loaded
isUrlLoaded = true;
}
}