1

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.

some_id
  • 29,466
  • 62
  • 182
  • 304

3 Answers3

3

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

rdelmar
  • 103,982
  • 12
  • 207
  • 218
1

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

Community
  • 1
  • 1
majorl3oat
  • 4,327
  • 1
  • 18
  • 21
0

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.

Yuliani Noriega
  • 1,085
  • 12
  • 23