質問

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?

役に立ちましたか?

解決 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/

他のヒント

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];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top