NSURLConnection to NSURLSession

NSURLConnection to NSURLSession

 got its start a decade ago, with the original release of Safari in 2003, as an abstraction on top of the Core Foundation / CFNetwork APIs. The name  actually refers to a group of the interrelated components that form the Foundation URL Loading System: , , , , , , and its namesake, .

 objects are passed to an  object. The delegate (conforming to the erstwhile informal  and  protocols) responds asynchronously as an , and any associated  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  object to seamlessly change loading behavior as necessary.

For better or worse,  has served as the networking infrastructure for hundreds of thousands of Cocoa and Cocoa Touch applications, and has held up rather well, considering. But over the years, emerging use cases–on the iPhone and iPad, especially–have challenged several core assumptions, and created cause for refactoring.

At WWDC 2013, Apple unveiled the successor to : .

NSURL *URL = [NSURL URLWithString:@"https://example.com/upload"]; NSURLRequest *request = [NSURLRequest requestWithURL:URL]; NSData *data = ...; NSURLSession *session = [NSURLSession sharedSession]; NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request fromData:data completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) { // ... }]; [uploadTask resume];

Kalidoss Shanmugam

Mobile App Developer | AI & ML Engineer | iOS (Swift, SwiftUI) | Android (Kotlin, Jetpack) | Python, LLM, React Native, Flutter | Mobile Automation (UITesting, Espresso)

8 年

Hi BhuShan PaWaR, Great Article, Thanks for your time.

回复
Rajan Maheshwari

Tech Lead(iOS) at Hindustan Times

8 年

Hi Try to post all the codes in swift rather than objective c that will be helpful for all.

要查看或添加评论,请登录

BhuShan PaWaR的更多文章

  • iOS 11?—?Core ML

    iOS 11?—?Core ML

    I introduced Core ML which is a general machine learning framework. Apple also provide frameworks for specific areas.

  • Protocol-oriented Programming in Swift

    Protocol-oriented Programming in Swift

    Protocols are used to define a “blueprint of methods, properties, and other requirements that suit a particular task or…

    1 条评论
  • iOS 10 Push Notifications

    iOS 10 Push Notifications

    Images, GIFs, Audio and Video You can now send rich media in a push notification, including images, GIFs, audio, and…

    3 条评论
  • Apple Keynote Event (September 7, 2016)

    Apple Keynote Event (September 7, 2016)

    Apple has launched the two new members of IPhone Family. iPhone 7 and iPhone 7 Plus.

  • Apple Pay

    Apple Pay

    Mobile payments are the hot phrase of the season. Since Apple Pay’s announcement in 2014 and now Samsung and…

  • IMPLEMENTING SPOTLIGHT IN YOUR APP

    IMPLEMENTING SPOTLIGHT IN YOUR APP

    Hey Readers, hope you have a great time reading the posts, today we will have a quick look at Spotlight search feature…

  • WHATS NEW IN IOS 9

    WHATS NEW IN IOS 9

    Multitasking Enhancements for iPAD For Multitasking on iPAD, iOS 9 has introduced bunch of new views which are : Slide…

    1 条评论
  • IOS9

    IOS9

    Apple has been always improvising the iOS & developer tools this time keeping in mind the smaller size devices like 8…

  • DEEP LINKING

    DEEP LINKING

    Deep Linking at first seems to be very heavy & new concept but its actually very useful. But lets first understand what…

  • ASPECT RATIOS & AUTOLAYOUT

    ASPECT RATIOS & AUTOLAYOUT

    Auto Layout at first seems to be very boring and unresponsive, did you felt the same ? The first time I started with I…

    1 条评论

社区洞察

其他会员也浏览了