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