只调用第一个请求 UIWebView
Call only first request UIWebView
我有一个 url 请求让我们说
let url = URL(string: "https://www.google.com/share?referCode=RSJDofpeW")
并且我们要在WebView中打开这个url,这个link也和通用的link关联。所以打开这个 url 将打开已安装的应用程序,但我想在 UIWebView 中加载页面。所以我检查了代表,发现第一次它调用它是上面的 url 然后下次它会添加方案和应用程序商店重定向。
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;
}
}
我有一个 url 请求让我们说
let url = URL(string: "https://www.google.com/share?referCode=RSJDofpeW")
并且我们要在WebView中打开这个url,这个link也和通用的link关联。所以打开这个 url 将打开已安装的应用程序,但我想在 UIWebView 中加载页面。所以我检查了代表,发现第一次它调用它是上面的 url 然后下次它会添加方案和应用程序商店重定向。
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;
}
}