Everybody Loves AFNetworking ... and So Can you!

8,116 views
7,850 views

Published on

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/

0 Comments
10 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
8,116
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
66
Comments
0
Likes
10
Embeds 0
No embeds

No notes for slide

Everybody Loves AFNetworking ... and So Can you!

  1. 1. Everybody Loves AFNetworking ...and So Can You!Mattt ThompsonHeroku
  2. 2. @mattt
  3. 3. AFHTTPClientJSON XML plist Image AFHTTPRequestOperation AFURLConnectionOperation
  4. 4. AFURLConnectionOperation
  5. 5. NSURLConnection + NSOperation
  6. 6. NSURLConnection• High-Level Networking API• Delegate-based Callbacks
  7. 7. URL Loading System• URL Loading • Authentication & Credentials • NSURLConnection • NSURLRequest • NSURLCredential • NSURLResponse • NSURLAuthenticationChallenge• Caching • Cookies • NSURLCache • NSHTTPCookie • NSURLCacheResponse • Protocols • NSProtocol
  8. 8. NSURLConnection Delegate Methods - connection:didReceiveResponse: - connection:didReceiveData: - connectionDidFinishLoading: - connection:didFailWithError: - connection:willCacheResponse:
  9. 9. NSOperation• Atomic Unit of Computation • Concurrently executed in NSOperationQueue• Encapsulates State • started, executing, finished• Cancelable• Completion Blocks
  10. 10. AFURLConnectionOperation• NSOperation Subclass• Implements NSURLConnection Delegate Methods• Supports Streaming Uploads / Downloads• Stores Request, Response, Data
  11. 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. 12. AFURLConnectionOperation
  13. 13. AFHTTPRequestOperationAFURLConnectionOperation
  14. 14. AFHTTPRequestOperation • AFURLConnectionOperation Subclass • Adds Knowledge Specific to HTTP • Status Codes • MIME Types • Adds Success / Failure Distinction
  15. 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. 16. AFHTTPRequestOperationAFURLConnectionOperation
  17. 17. JSON XML plist Image AFHTTPRequestOperation AFURLConnectionOperation
  18. 18. Operations should encapsulate everything ittakes to get what you want
  19. 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. 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. 21. NSURL *URL = [NSURL URLWithString:@"http://example.com/avatar.jpg"];[cell.imageView setImageWithURL:URL placeholderImage:[UIImage imageNamed:@"placeholder"]];
  22. 22. JSON XML plist Image AFHTTPRequestOperation AFURLConnectionOperation
  23. 23. AFHTTPClientJSON XML plist Image AFHTTPRequestOperation AFURLConnectionOperation
  24. 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. 25. • Create NSURLRequest• Create AFHTTPRequestOperation• Enqueue Operations
  26. 26. AFHTTPClientJSON XML plist Image AFHTTPRequestOperation AFURLConnectionOperation
  27. 27. Collection UIKit +JSON Extensions OAuth AFHTTPClient JSON XML plist Image S3 AFHTTPRequestOperation AFURLConnectionOperation
  28. 28. AFNetworking Ecosystem• AFOAuth1Client & AFOAuth2Client• AFAmazonS3Client• AFDownloadRequestOperation• AFIncrementalStore• AFKissXMLRequestOperation• AFCollectionJSONRequestOperation• AFHTTPRequestOperationLogger
  29. 29. AFFuture• Working Towards 1.0• AFIncrementalStore• More Examples & Documentation• Modular CocoaPods Specification
  30. 30. How You Can Help• Documentation & Guides • Especially non-English• Pitch In on Stack Overflow• Issues• Pull Requests
  31. 31. Thanks!

×