2014-01-28 190 views
1

我已經爲iOS構建了一個Web瀏覽器,並且正在嘗試將該URL拉到地址欄中顯示。
我看看NSURLRequest中的webView:shouldStartLoadWithRequest:navigationType:webViewDidFinishLoad:UIWebView委託方法。NSURLRequest的mainDocumentURL和URL屬性有什麼區別?

爲此,我應該使用NSURLRequestURLmainDocumentURL屬性,它們有什麼區別?

回答

1

該文檔不是很清楚,但似乎mainDocumentURL用於cookie策略內部。

NSHTTPCookieStorage Class Reference > setCookies:forURL:mainDocumentURL:

mainDocumentURL

主HTML文檔的用於頂級框的URL(如果已知)。可以是零。如果Cookie接受策略是NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain,則該URL用於確定Cookie是否應該被接受。

如果您使用的URL可能是嵌入在HTML文檔中的子框架或某種媒體類型,那麼您可能想知道mainDocumentURL是什麼;否則,只需使用URL。

3

您想使用URL

mainDocumentURL將在加載頁面的子部分(如圖像,腳本等)時用於告知系統加載這些子部分時可以安全使用哪些Cookie。無論如何,這並不是你想要展示的內容,並且記錄在當前版本的框架中未被使用。

/*! 
    @method mainDocumentURL 
    @abstract The main document URL associated with this load. 
    @discussion This URL is used for the cookie "same domain as main 
    document" policy. There may also be other future uses. 
    See setMainDocumentURL: 
    NOTE: In the current implementation, this value is unused by the 
    framework. A fully functional version of this method will be available 
    in the future. 
    @result The main document URL. 
*/ 
+0

該文檔在哪裏說它是未使用的?它看起來像我運行的測試中沒有設置該URL,並且在某些情況下在webView中設置了mainDocumentURL:shouldStartLoadWithRequest:navigationType:delegate方法。 – Austin

+0

我不清楚NSURLRequest如何加載任何東西,如果它沒有URL加載,但我不是這個領域的專家。 –

+0

我會建議使用mainDocumentURL而不是URL。事實上,URL可以引用UIWebView當前顯示的網站的子部分。 – Joss

相關問題