2016-11-25 62 views
0

我有一個URL請求讓說呼叫僅第一個請求的UIWebView

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

,我們要打開這個網址中的WebView而這個鏈接也與通用的聯繫有關。所以打開這個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-appssgoogleApp它不會加載請求,但在第一次時,它是正確的網址應該加載該頁面但未打開。

回答

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

試過,但該頁面沒有加載 –

+0

@ParthAdroja我編輯試圖知道 –

+0

您最近編輯將使ITMS,應用程序和googleApp打開而不是網頁。 –

相關問題