【问题标题】:Call only first request UIWebView只调用第一个请求 UIWebView
【发布时间】:2016-11-25 09:13:47
【问题描述】:

我有一个网址请求让我们说

        let url = URL(string: "https://www.google.com/share?referCode=RSJDofpeW")

我们想在 WebView 中打开这个 url,这个链接也与通用链接相关联。所以打开这个 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-appssgoogleApp 时,它不会加载请求,而是第一次加载正确的 url应该加载该页面,但未打开。

【问题讨论】:

    标签: ios uiwebview swift3 deep-linking


    【解决方案1】:

    //检查

     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;
                }
            }
    

    【讨论】:

    • 试过了,但页面没有加载
    • 您最近的编辑将使 itms-apps 和 googleApp 打开而不是网页。
    • 首先这个网址会点击google.com/share?referCode=RSJDofpeW,然后是itms和googleApp
    猜你喜欢
    • 1970-01-01
    • 2015-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-16
    相关资源
    最近更新 更多