1

I'm using AFNetworking for my app. I want to create a queue mechanism with different priority for each HTTP request. For that - I need to be able to create an HTTP Request using AFNetowrking but use it later.

The example for creating an HTTP request is:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

This code will send the request immediately. How can I just create the request (method, parameters, url), but use it at a later time?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
YogevSitton
  • 10,068
  • 11
  • 62
  • 95

2 Answers2

4

Check operationQueue of AFHTTPRequestOperationManager. If you suspend it before adding request, it will not run until you resume operation queue. For example:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager.operationQueue setSuspended:YES];
Dmitry Volkov
  • 500
  • 1
  • 3
  • 14
-2

Turns out you need to create an AFHTTPRequestOperation instead of a manager.

Full article here: http://samwize.com/2012/10/25/simple-get-post-afnetworking/

YogevSitton
  • 10,068
  • 11
  • 62
  • 95
  • 4
    That article is about AFNetworking 1.x. Only AFNetworking 1.x has AFHTTPClient. The question is about AFNetworking 2.x, which has AFHTTPRequestOperationManager. – user102008 Jan 21 '14 at 07:51