What is the biggest difference between NSURLConnection and NSURLSession

前端 未结 3 1201
再見小時候
再見小時候 2020-12-02 19:10

NSURLSession is new network SDK than NSURLConnection from Apple. 3rd old choice is CFNetwork.

Question here is to figure out the biggest difference between them to u

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 19:19

    NSURLConnection

    A group of the interrelated components that form the Foundation URL Loading System: NSURLRequest, NSURLResponse, NSURLProtocol, NSURLCache, NSHTTPCookieStorage, NSURLCredentialStorage, and its namesake, NSURLConnection

    NSURLRequest objects are passed to an NSURLConnection object. The delegate (conforming to the erstwhile informal and protocols) responds asynchronously as an NSURLResponse, and any associated NSData are sent from the server

    Before a request is sent to the server, the shared cache is consulted, and depending on the policy and availability, a cached response may be returned immediately and transparently. If no cached response is available, the request is made with the option to cache its response for any subsequent requests. In the process of negotiating a request to a server, that server may issue an authentication challenge, which is either handled automatically by the shared cookie or credential storage, or by the connection delegate. Outgoing requests could also be intercepted by a registered NSURLProtocol object to seamlessly change loading behavior as necessary.

    NSURLSession

    refers to a group of interdependent classes, in addition to the eponymous class NSURLSession. NSURLSession is comprised of the same pieces as before, with NSURLRequest, NSURLCache, and the like, but replaces NSURLConnection with NSURLSession, NSURLSessionConfiguration, and three subclasses of NSURLSessionTask: NSURLSessionDataTask, NSURLSessionUploadTask, and NSURLSessionDownloadTask.

    NSURLSessionTask is an abstract subclass, with three concrete subclasses that are used directly: NSURLSessionDataTask, NSURLSessionUploadTask, and NSURLSessionDownloadTask. These three classes encapsulate the three essential networking tasks of modern applications: fetching data, such as JSON or XML, and uploading and downloading files.for more

提交回复
热议问题