1. NSURL伦吠,代表的是一個(gè)資源的地址虱疏,可以是網(wǎng)絡(luò)資源惹骂、本地資源、書簽等等做瞪。
An NSURL object represents a URL that can potentially contain the location of a resource on a remote server, the path of a local file on disk, or even an arbitrary piece of encoded data.
? ? 可以從中提取scheme析苫、host、query等值穿扳。
2. NSURLRequest衩侥,代表是一個(gè)網(wǎng)絡(luò)請求,主要包含NSURL和從NSURL獲取內(nèi)容的緩存策略矛物。
NSURLRequest objects represent a URL load request in a manner independent of protocol and URL scheme.
? ? 可以通過NSMutableURLRequest設(shè)置請求的Header茫死、Method、Body等值履羞。
3. NSURLConnection峦萎,代表一個(gè)網(wǎng)絡(luò)連接。
An NSURLConnection object lets you load the contents of a URL by providing a URL request object. The interface for NSURLConnection is sparse, providing only the controls to start and cancel asynchronous loads of a URL request. You perform most of your configuration on the URL request object itself.
? ? 可以用來發(fā)送同步或者異步請求忆首,或者通過NSURLConnectionDataDelegate的方式來進(jìn)行更加精確的控制爱榔。比如可以用來顯示下載文件的進(jìn)度,這是Demo糙及。
4. NSURLSession详幽,從iOS7之后提供的代替NSURLConnection的方案。
The NSURLSession class and related classes provide an API for downloading content. This API provides a rich set of delegate methods for supporting authentication and gives your app the ability to perform background downloads when your app is not running or, in iOS, while your app is suspended.
? ? 提供了安全驗(yàn)證和證書機(jī)制浸锨,能夠在App進(jìn)入后臺(tái)之后進(jìn)行上傳或者下載任務(wù)唇聘,用一個(gè)session來管理一些任務(wù),提供了更多的deletege方法和相關(guān)任務(wù)類進(jìn)行更加精確的控制柱搜,通過NSURLSessionConfiguration對session進(jìn)行配置迟郎,session中的所有task共享同一個(gè)配置,值得一提的是NSURLSession保持著對delegate和task的強(qiáng)引用聪蘸,調(diào)用完成之后需要調(diào)用invalidate相關(guān)方法宪肖,否則會(huì)造成內(nèi)存泄漏。這里提供了一個(gè)演示的Demo健爬。
5. NSURLSessionConfiguration控乾,對NSURLSession提供配置,包括緩存策略浑劳、超時(shí)等阱持。
An NSURLSessionConfiguration object defines the behavior and policies to use when uploading and downloading data using an?NSURLSession?object. When uploading or downloading data, creating a configuration object is always the first step you must take. You use this object to configure the timeout values, caching policies, connection requirements, and other types of information that you intend to use with your NSURLSession object.
6. NSURLSessionTask,一個(gè)任務(wù)對應(yīng)一個(gè)request魔熏,task可以restart衷咽,而NSURLConnection只能啟動(dòng)一次。這是其他Task的基類:NSURLSessionDataTask提供一般形式的NSData的請求蒜绽;NSURLSessionUploadTask:提供上傳feature并能在App suspended的情況下執(zhí)行镶骗;NSURLSessionDownloadTask:提供下載feature并能在App suspended的情況下執(zhí)行。
相關(guān)資料:
1.?NSURLConnection Class Reference
2.?NSURLSession Class Reference
4.?From NSURLConnection to NSURLSession
6.?SPDY