1. NSURL,代表的是一個資源的地址,可以是網(wǎng)絡資源、本地資源、書簽等等。
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,代表是一個網(wǎng)絡請求,主要包含NSURL和從NSURL獲取內容的緩存策略。
NSURLRequest objects represent a URL load request in a manner independent of protocol and URL scheme.
? ? 可以通過NSMutableURLRequest設置請求的Header、Method、Body等值。
3. NSURLConnection,代表一個網(wǎng)絡連接。
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的方式來進行更加精確的控制。比如可以用來顯示下載文件的進度,這是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.
? ? 提供了安全驗證和證書機制,能夠在App進入后臺之后進行上傳或者下載任務,用一個session來管理一些任務,提供了更多的deletege方法和相關任務類進行更加精確的控制,通過NSURLSessionConfiguration對session進行配置,session中的所有task共享同一個配置,值得一提的是NSURLSession保持著對delegate和task的強引用,調用完成之后需要調用invalidate相關方法,否則會造成內存泄漏。這里提供了一個演示的Demo。
5. NSURLSessionConfiguration,對NSURLSession提供配置,包括緩存策略、超時等。
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,一個任務對應一個request,task可以restart,而NSURLConnection只能啟動一次。這是其他Task的基類:NSURLSessionDataTask提供一般形式的NSData的請求;NSURLSessionUploadTask:提供上傳feature并能在App suspended的情況下執(zhí)行;NSURLSessionDownloadTask:提供下載feature并能在App suspended的情況下執(zhí)行。
相關資料:
1.?NSURLConnection Class Reference
2.?NSURLSession Class Reference
4.?From NSURLConnection to NSURLSession
6.?SPDY