Everybody Loves AFNetworking ... and So Can you!

of 32
73 views
PDF
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Document Description
Brooklyn iOS Developer Meetup Presenter: Mattt Thompson Topic: Everybody loves AFNetworking Location: NYU Poly Incubator DUMBO Brooklyn, NY http://www.meetup.com/The-Brooklyn-iPhone-and-iPad-Developer-Meetup/
Document Share
Document Transcript
  • 1. Everybody Loves AFNetworking ...and So Can You!Mattt ThompsonHeroku
  • 2. @mattt
  • 3. AFHTTPClientJSON XML plist Image AFHTTPRequestOperation AFURLConnectionOperation
  • 4. AFURLConnectionOperation
  • 5. NSURLConnection + NSOperation
  • 6. NSURLConnection• High-Level Networking API• Delegate-based Callbacks
  • 7. URL Loading System• URL Loading • Authentication & Credentials • NSURLConnection • NSURLRequest • NSURLCredential • NSURLResponse • NSURLAuthenticationChallenge• Caching • Cookies • NSURLCache • NSHTTPCookie • NSURLCacheResponse • Protocols • NSProtocol
  • 8. NSURLConnection Delegate Methods - connection:didReceiveResponse: - connection:didReceiveData: - connectionDidFinishLoading: - connection:didFailWithError: - connection:willCacheResponse:
  • 9. NSOperation• Atomic Unit of Computation • Concurrently executed in NSOperationQueue• Encapsulates State • started, executing, finished• Cancelable• Completion Blocks
  • 10. AFURLConnectionOperation• NSOperation Subclass• Implements NSURLConnection Delegate Methods• Supports Streaming Uploads / Downloads• Stores Request, Response, Data
  • 11. NSURL *URL = [NSURL URLWithString:@"http://httpbin.org/ip"];NSURLRequest *request = [NSURLRequest requestWithURL:URL];AFURLConnectionOperation *operation = [[AFURLConnectionOperation alloc] initWithRequest:request];operation.completionBlock = ^ { NSLog(@"Complete: %@", operation.responseString);};[operation start];
  • 12. AFURLConnectionOperation
  • 13. AFHTTPRequestOperationAFURLConnectionOperation
  • 14. AFHTTPRequestOperation • AFURLConnectionOperation Subclass • Adds Knowledge Specific to HTTP • Status Codes • MIME Types • Adds Success / Failure Distinction
  • 15. NSURL *URL = [NSURL URLWithString:@"http://httpbin.org/robots.txt"];NSURLRequest *request = [NSURLRequest requestWithURL:URL];AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];[operation setCompletionBlockWithSuccess: ^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Success: %@", operation.responseString);} failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Failure: %@", error);}];[operation start];
  • 16. AFHTTPRequestOperationAFURLConnectionOperation
  • 17. JSON XML plist Image AFHTTPRequestOperation AFURLConnectionOperation
  • 18. Operations should encapsulate everything ittakes to get what you want
  • 19. Success / Failure JSON XML ImageStatus 2XX 2XX 2XXCode image/tiffContent application/json text/json application/xml image/jpeg Type text/javascript text/xml image/gif image/png
  • 20. NSURL *URL = [NSURL URLWithString:@"http://httpbin.org/get"];NSURLRequest *request = [NSURLRequest requestWithURL:URL];AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, idJSON) { NSLog(@"Success :%@", JSON); } failure:^(NSURLRequest *request, NSHTTPURLResponse *response,NSError *error, id JSON) { NSLog(@"Failure: %@", error); }];[operation start];
  • 21. NSURL *URL = [NSURL URLWithString:@"http://example.com/avatar.jpg"];[cell.imageView setImageWithURL:URL placeholderImage:[UIImage imageNamed:@"placeholder"]];
  • 22. JSON XML plist Image AFHTTPRequestOperation AFURLConnectionOperation
  • 23. AFHTTPClientJSON XML plist Image AFHTTPRequestOperation AFURLConnectionOperation
  • 24. AFHTTPClient• Designed to Work for Single Endpoint• Set Default Headers • Authorization, Accept, Accept-Language, etc.• Encode Parameters to Query String or Message Body• Handle Multipart Form Request Body Construction• Manage Request Operations
  • 25. • Create NSURLRequest• Create AFHTTPRequestOperation• Enqueue Operations
  • 26. AFHTTPClientJSON XML plist Image AFHTTPRequestOperation AFURLConnectionOperation
  • 27. Collection UIKit +JSON Extensions OAuth AFHTTPClient JSON XML plist Image S3 AFHTTPRequestOperation AFURLConnectionOperation
  • 28. AFNetworking Ecosystem• AFOAuth1Client & AFOAuth2Client• AFAmazonS3Client• AFDownloadRequestOperation• AFIncrementalStore• AFKissXMLRequestOperation• AFCollectionJSONRequestOperation• AFHTTPRequestOperationLogger
  • 29. AFFuture• Working Towards 1.0• AFIncrementalStore• More Examples & Documentation• Modular CocoaPods Specification
  • 30. How You Can Help• Documentation & Guides • Especially non-English• Pitch In on Stack Overflow• Issues• Pull Requests
  • 31. Thanks!
  • We Need Your Support
    Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

    Thanks to everyone for your continued support.

    No, Thanks
    SAVE OUR EARTH

    We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

    More details...

    Sign Now!

    We are very appreciated for your Prompt Action!

    x