2016-02-08 94 views
1

我使用SFSafariViewController在iOS的應用9我用斯威夫特2.safariViewController調試 - 網址不加載

我試圖打開它由於某種原因失敗的URL建設。所有其他網址我試過的作品,除了這一個:

http://www.ctvnews.ca/sci-tech/33-engineers-to-be-recognized-at-sci-tech-oscars-1.2730223

的URL是在普通的移動Safari瀏覽器罰款模擬器,在我的iPhone,我的iPad,在任何桌面瀏覽器。只是當我嘗試在這個應用程序中通過Swift訪問它時,它失敗了。

代碼如下:

func openInSafari(URLtoOpen: String) { 
     print("Trying to openURL: " + URLtoOpen) 
     let safariVC = SFSafariViewController(URL:NSURL(string: URLtoOpen)!, entersReaderIfAvailable: false) 
     safariVC.delegate = self 
     self.presentViewController(safariVC, animated: true, completion: nil) 
    } 

    func safariViewController(controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) { 
     // SFSafariViewController will present an error message in the browser, 
     // but in this case we will dismiss the view controller and present our 
     // own error alert. 
     if didLoadSuccessfully == false { 
      controller.dismissViewControllerAnimated(true, completion: { [unowned self]() -> Void in 
       let alert = UIAlertController(title: "Could Not Load", message: "The URL could not be loaded.", preferredStyle: .Alert) 
       alert.addAction(UIAlertAction(title: "Okay", style: .Default, handler: nil)) 
       self.presentViewController(alert, animated: true, completion: nil) 
      }) 
     } 
    } 

此代碼工作正常,並且,正如我所說的,其他的URL負載就好了。我真正需要的只是一種更加詳細地調試safariViewController遇到的問題的方式,這會導致它失敗。

didLoadSuccessfully == false行似乎並沒有提供更多的調試選項,以瞭解出了什麼問題。

換句話說,我該如何調試?我似乎無法在蘋果的文檔中找到任何解釋加載錯誤時要檢查的內容。

請幫忙! 謝謝。

+0

可以肯定的是,您爲不安全的請求添加了ATS異常? – jcaron

+0

我在開發過程中添加了ATS異常,是的。 – SH10151

+0

沒有顯示在日誌中? 'didCompleteInitialLoad'確實用'didLoadSuccessfully'調用了false?如果你讓它顯示自己的錯誤信息,它是否說有用? – jcaron

回答

0

SFSafariViewController自動屏蔽了應用程序(如果它實際上是一個不同的過程,我不會感到驚訝),並且出於隱私和安全原因,與應用程序共享的信息非常少。

你可以嘗試的是加載相同的基於UIWebViewWKWebView(它給你更多的反饋,但不與Safari共享cookie或密碼),看看會發生什麼。