iOS7 introduces Nsurlsession, which can support the new features of background-related network operations. Let's see what it's good for:1. Background upload and download;2. No need to pass the nsoperation, we can use the Nsurlsession API to do network operation pause and recovery. 3. As a configurable container: for example, you can set some properties of the HTTP header and save it in the session, you don't have to repeat the configuration; don ' t repeat yourself~4. Can be sub-class and support private storage;5. An improvement has been made to the authentication callback, which could have come from any request, and now each request can be processed in the specified proxy method, after the Nsurlconnection authentication callback could not match the request .
The translation material is as follows: (from Link: http://www.raywenderlich.com/51127/nsurlsession-tutorial)Why use Nsurlsession?
why Should you use nsurlsession ? Well, it brings you a number of new advantages and benefits:
- Background uploads and downloads: with just a configuration option When The
nsurlsession is created, you get all the benefits of background networking. This helps with battery life, supports UIKit multitasking and uses the same delegate model as in-process transfers.
- ability to pause and resume networking operations: as you'll see Later, with the Nsurlsession API (any) networking task can be paused, stopped, and restarted. No nsoperation sub-classing necessary.
- configurable container: each
nsurlsession is the configurable container for putting requests into. For example, if you need to set a HTTP header option you'll only need to does this once and each request in the session W Ill has the same configuration.
- subclassable and private storage:
NSURLSession Is subclassable and you can configure a session to use private storage on a per session basis. This allows-storage objects outside of the global state.
-
Improved authentication handling:Authentication is do on a specific connection basis. When usingNSURLConnectionIf an authentication challenge is issued, the challenge would come back for a arbitrary request, you wouldn ' t know exact Ly what request was getting the challenge. WithNSURLSession, the delegate handles authentication.