Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AFNetworking 2.0 + NSURLSession

chrisfsampaio
September 28, 2013

AFNetworking 2.0 + NSURLSession

chrisfsampaio

September 28, 2013
Tweet

Other Decks in Programming

Transcript

  1. “A delightful networking framework for iOS and OSX.” “AFNetworking is

    one of the most widely used open source projects for iOS and Mac OS X development.” “With over 8,700 stars, 2,200 forks, and 130 contributors, the project is also among the most active and influential in the community.”
  2. That’s it! A Network API builded on top of Network

    Foundation that takes care of the hard work and gives you friendly interfaces.
  3. NSURLSessionConfiguration Cache Policy Timeout Interval Allows Celullar Network Cookies Storage

    NSURLCache *You cannot modify a configuration after your session was created
  4. NSURLSessionConfiguration Default configuration: Disk-based cache, credentials on the user keychain

    Ephemeral configuration: All caches, credentials storage, and so on are kept in RAM and dies when the session is invalidated. Background configuration: Similar to default, supports requests while app is suspended
  5. NSURLSessionDataTask: - Used to send/receive data using NSData objects -

    Not backgroundable NSURLSessionDownloadTask: - Donwloads data into a local file - Backgroundable NSURLSessionUploadTask: - Uploads data from a local file - Backgroundable *Performed asynchronously by default
  6. NSURLSessionDelegate • URLSession:didBecomeInvalidWithError: • URLSession:didReceiveChallenge:completionHandler: NSURLSessionTaskDelegate • URLSession:willPerformHTTPRedirection:newRequest:completionHandler: • URLSession:task:didReceiveChallenge:completionHandler:

    • URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend: • URLSession:task:didCompleteWithError: NSURLSessionDataDelegate • URLSession:dataTask:didReceiveResponse:completionHandler: • URLSession:dataTask:didBecomeDownloadTask: • URLSession:dataTask:didReceiveData: • URLSession:dataTask:willCacheResponse:completionHandler: NSURLSessionDownloadDelegate • URLSession:downloadTask:didFinishDownloadingToURL: • URLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesWritten: totalBytesExpectedToWrite: • URLSession:downloadTask:didResumeAtOffset:expectedTotalBytes:
  7. iOS 6 and Mac OS X 10.8 Moutain Lion Xcode

    5 NSURLSession & NSURLConnection Serialization Modules UIKit Extensions Realtime
  8. Coming from 1.0... Will keep compatibilty with NSURLConnection and NSURLSession

    at the same time No more AFHTTPClient - Too many roles to one class, this was split up into another classes
  9. AFHTTPSessionManager ◦ NSURLSesssion *managedSession; ◦ NSURL *baseURL; - Provides methods

    for HTTP requests (GET, POST, PUT, etc) with serialized response and request. - No NSData handling
  10. - Shared between operations and tasks - Protocols instead of

    subclasses - More pluggable to specific needs
  11. Coming from AFHTTPClient... - Follows the new serializer concept -

    HTTP request methods (GET, POST, etc) now returns the operation that was just created.
  12. - No more classes for each kind of serializer. (Also

    follows the new serializer concept)
  13. AFNetworkReachabilityManager - Monitors network status while providing notifications and callbacks

    blocks for status changes. - A property of AFURLSessionManager and AFURLConnectionManager