some_id
some_id

Reputation: 29906

Using NSURLConnecion delegates with NSURLConnection +sendAsynchronousRequest

How does one use NSURLConnection delegate callbacks when using the

+ (void)sendAsynchronousRequest:(NSURLRequest *)request
                      queue:(NSOperationQueue*) queue
          completionHandler:(void (^)(NSURLResponse*, NSData*, NSError*))

method?

I would like to be able to access the caching delegate callback on the queue handling the completion block.

Upvotes: 1

Views: 2571

Answers (3)

majorl3oat
majorl3oat

Reputation: 4347

Just use it like this

NSURL *url = [NSURL URLWithString:kURL];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL      :   url
                                                        cachePolicy     :   NSURLRequestReloadIgnoringCacheData
                                                        timeoutInterval :   30];
NSString *params = [NSString stringWithFormat:@"param=%d",digits];

[request setHTTPMethod:@"POST"];
[request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];

[NSURLConnection sendAsynchronousRequest:request 
                                   queue:[NSOperationQueue mainQueue]  
                       completionHandler:^(NSURLResponse *response, NSData *taxiData, NSError *error) {

 //Snippet - Do sth. (block)

}

Hope this help.

EDIT: Sorry, I didn't read your question clearly. +sendAsynchronousRequest did not require delegates method.

EDIT2: or, maybe, this will help you

Upvotes: 1

Yuliani Noriega
Yuliani Noriega

Reputation: 1083

In order to use delegate methods with NSURLConnection you need to instantiate a NSURLConnection variable. Since

+ (void)sendAsynchronousRequest:(NSURLRequest *)request
                  queue:(NSOperationQueue*) queue
      completionHandler:(void (^)(NSURLResponse*, NSData*, NSError*))

is a superclass method you can't use it.

Upvotes: 0

rdelmar
rdelmar

Reputation: 104092

You don't. You need to use the NSURLConnection method, initWithRequest:delegate:, instead of sendAsynchronousRequest, to use the delegate call back methods.

Upvotes: 3

Related Questions