通過URL訪問創(chuàng)建網(wǎng)絡請求

先看代碼:

NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:(NSURLRequestCAchePolicy) timeoutInterval:(NSTiemInterval)  ]

這里第一個參數(shù)沒啥好說的具體說說第二個參數(shù) NSURLRequestCAchePolicy

  NSURLRequestUseProtocolCachePolicy = 0,
   NSURLRequestReloadIgnoringLocalCacheData = 1,
   NSURLRequestReloadIgnoringLocalAndRemoteCacheData = 4, // Unimplemented
   NSURLRequestReloadIgnoringCacheData =    NSURLRequestReloadIgnoringLocalCacheData,
    NSURLRequestReturnCacheDataElseLoad = 2,
    NSURLRequestReturnCacheDataDontLoad = 3,
    NSURLRequestReloadRevalidatingCacheData = 5, 

我們會看到5個枚舉類型下面一一來解釋下
首先看看xcode的英文解釋

@discussion The NSURLRequestCachePolicy enum defines constants that
    can be used to specify the type of interactions that take place with
    the caching system when the URL loading system processes a request.
    Specifically, these constants cover interactions that have to do
    with whether already-existing cache data is returned to satisfy a
    URL load request.

中文翻譯:

    @constant NSURLRequestUseProtocolCachePolicy Specifies that the
    caching logic defined in the protocol implementation, if any, is
    used for a particular URL load request. This is the default policy
    for URL load requests.

中文翻譯:基礎策略

 @constant NSURLRequestReloadIgnoringLocalCacheData Specifies that the
    data for the URL load should be loaded from the origin source. No
    existing local cache data, regardless of its freshness or validity,
    should be used to satisfy a URL load request.

中文翻譯:忽略本地緩存

    @constant NSURLRequestReloadIgnoringLocalAndRemoteCacheData Specifies that
    not only should the local cache data be ignored, but that proxies and
    other intermediates should be instructed to disregard their caches
    so far as the protocol allows.  Unimplemented.

中文翻譯:無視任何緩存策略,無論是本地的還是遠程的亭枷,總是從原地址重新下載

  @constant NSURLRequestReloadIgnoringCacheData Older name for
    NSURLRequestReloadIgnoringLocalCacheData.

中文翻譯:
NSURLRequestReloadIgnoringCacheData 是 NSURLRequestReloadIgnoringLocalCacheData 的舊名役衡,這兩個是一樣的

    @constant NSURLRequestReturnCacheDataElseLoad Specifies that the
    existing cache data should be used to satisfy a URL load request,
    regardless of its age or expiration date. However, if there is no
    existing data in the cache corresponding to a URL load request,
    the URL is loaded from the origin source.

中文翻譯:首先使用緩存,如果沒有本地緩存姥闪,才從原地址下載

  @constant NSURLRequestReturnCacheDataDontLoad  Specifies that the
    existing cache data should be used to satisfy a URL load request,
    regardless of its age or expiration date. However, if there is no
    existing data in the cache corresponding to a URL load request, no
    attempt is made to load the URL from the origin source, and the
    load is considered to have failed. This constant specifies a
    behavior that is similar to an "offline" mode.

中文翻譯:使用本地緩存迎捺,從不下載,如果本地沒有緩存,則請求失敗俄周,此策略多用于離線操作

    @constant NSURLRequestReloadRevalidatingCacheData Specifies that
    the existing cache data may be used provided the origin source
    confirms its validity, otherwise the URL is loaded from the
    origin source.  Unimplemented.

中文翻譯:如果本地緩存是有效的則不下載,其他任何情況都從原地址重新下載
</code>

第三個參數(shù)就是設置延遲時間髓迎,也就是你等他響應的時間峦朗。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市排龄,隨后出現(xiàn)的幾起案子波势,更是在濱河造成了極大的恐慌,老刑警劉巖橄维,帶你破解...
    沈念sama閱讀 217,509評論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件尺铣,死亡現(xiàn)場離奇詭異,居然都是意外死亡争舞,警方通過查閱死者的電腦和手機凛忿,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,806評論 3 394
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來竞川,“玉大人店溢,你說我怎么就攤上這事叁熔。” “怎么了逞怨?”我有些...
    開封第一講書人閱讀 163,875評論 0 354
  • 文/不壞的土叔 我叫張陵者疤,是天一觀的道長福澡。 經(jīng)常有香客問我叠赦,道長,這世上最難降的妖魔是什么革砸? 我笑而不...
    開封第一講書人閱讀 58,441評論 1 293
  • 正文 為了忘掉前任除秀,我火速辦了婚禮,結果婚禮上算利,老公的妹妹穿的比我還像新娘册踩。我一直安慰自己,他們只是感情好效拭,可當我...
    茶點故事閱讀 67,488評論 6 392
  • 文/花漫 我一把揭開白布暂吉。 她就那樣靜靜地躺著,像睡著了一般缎患。 火紅的嫁衣襯著肌膚如雪慕的。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,365評論 1 302
  • 那天挤渔,我揣著相機與錄音肮街,去河邊找鬼。 笑死判导,一個胖子當著我的面吹牛嫉父,可吹牛的內容都是我干的。 我是一名探鬼主播眼刃,決...
    沈念sama閱讀 40,190評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼绕辖,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了擂红?” 一聲冷哼從身側響起仪际,我...
    開封第一講書人閱讀 39,062評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎篮条,沒想到半個月后弟头,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,500評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡涉茧,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,706評論 3 335
  • 正文 我和宋清朗相戀三年赴恨,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片伴栓。...
    茶點故事閱讀 39,834評論 1 347
  • 序言:一個原本活蹦亂跳的男人離奇死亡伦连,死狀恐怖雨饺,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情惑淳,我是刑警寧澤额港,帶...
    沈念sama閱讀 35,559評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站歧焦,受9級特大地震影響移斩,放射性物質發(fā)生泄漏。R本人自食惡果不足惜绢馍,卻給世界環(huán)境...
    茶點故事閱讀 41,167評論 3 328
  • 文/蒙蒙 一向瓷、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧舰涌,春花似錦猖任、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,779評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至搁痛,卻和暖如春长搀,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背落追。 一陣腳步聲響...
    開封第一講書人閱讀 32,912評論 1 269
  • 我被黑心中介騙來泰國打工盈滴, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人轿钠。 一個月前我還...
    沈念sama閱讀 47,958評論 2 370
  • 正文 我出身青樓巢钓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親疗垛。 傳聞我的和親對象是個殘疾皇子症汹,可洞房花燭夜當晚...
    茶點故事閱讀 44,779評論 2 354

推薦閱讀更多精彩內容