31 | | Core |
32 |
33 | | AFURLConnectionOperation |
34 | An NSOperation that implements the NSURLConnection delegate methods. |
35 |
36 |
37 | | HTTP Requests |
38 |
39 |
40 | | AFHTTPRequestOperation |
41 | A subclass of AFURLConnectionOperation for requests using the HTTP or HTTPS protocols. It encapsulates the concept of acceptable status codes and content types, which determine the success or failure of a request. |
42 |
43 |
44 | | AFJSONRequestOperation |
45 | A subclass of AFHTTPRequestOperation for downloading and working with JSON response data. |
46 |
47 |
48 | | AFXMLRequestOperation |
49 | A subclass of AFHTTPRequestOperation for downloading and working with XML response data. |
50 |
51 |
52 | | AFPropertyListRequestOperation |
53 | A subclass of AFHTTPRequestOperation for downloading and deserializing objects with property list response data. |
54 |
55 |
56 | | HTTP Client |
57 |
58 | | AFHTTPClient |
59 |
60 | Captures the common patterns of communicating with an web application over HTTP, including:
61 |
62 |
63 | - Making requests from relative paths of a base URL
64 | - Setting HTTP headers to be added automatically to requests
65 | - Authenticating requests with HTTP Basic credentials or an OAuth token
66 | - Managing an NSOperationQueue for requests made by the client
67 | - Generating query strings or HTTP bodies from an NSDictionary
68 | - Constructing multipart form requests
69 | - Automatically parsing HTTP response data into its corresponding object representation
70 | - Monitoring and responding to changes in network reachability
71 |
72 | |
73 |
74 |
75 | | Images |
76 |
77 | | AFImageRequestOperation |
78 | A subclass of AFHTTPRequestOperation for downloading and processing images. |
79 |
80 |
81 | | UIImageView+AFNetworking |
82 | Adds methods to UIImageView for loading remote images asynchronously from a URL. |
83 |
84 |
85 |
86 | ## Example Usage
87 |
88 | ### XML Request
89 |
90 | ``` objective-c
91 | NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://api.flickr.com/services/rest/?method=flickr.groups.browse&api_key=b6300e17ad3c506e706cb0072175d047&cat_id=34427469792%40N01&format=rest"]];
92 | AFXMLRequestOperation *operation = [AFXMLRequestOperation XMLParserRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser) {
93 | XMLParser.delegate = self;
94 | [XMLParser parse];
95 | } failure:nil];
96 | [operation start];
97 | ```
98 |
99 | ### Image Request
100 |
101 | ``` objective-c
102 | UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)];
103 | [imageView setImageWithURL:[NSURL URLWithString:@"http://i.imgur.com/r4uwx.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder-avatar"]];
104 | ```
105 |
106 | ### API Client Request
107 |
108 | ``` objective-c
109 | // AFAppDotNetAPIClient is a subclass of AFHTTPClient, which defines the base URL and default HTTP headers for NSURLRequests it creates
110 | [[AFAppDotNetAPIClient sharedClient] getPath:@"stream/0/posts/stream/global" parameters:nil success:^(AFHTTPRequestOperation *operation, id JSON) {
111 | NSLog(@"App.net Global Stream: %@", JSON);
112 | } failure:nil];
113 | ```
114 |
115 | ### File Upload with Progress Callback
116 |
117 | ``` objective-c
118 | NSURL *url = [NSURL URLWithString:@"http://api-base-url.com"];
119 | AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
120 | NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"avatar.jpg"], 0.5);
121 | NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"/upload" parameters:nil constructingBodyWithBlock: ^(id