Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Track redirects when using sendAsynchronousRequest:queue:completionHandler:?

How can I invoke custom code when a redirect happens while sending a request with the method:

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

?

I'm looking to replicate the behavior the NSURLConnectionDelegate method:

- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
like image 799
Andy Obusek Avatar asked Nov 13 '22 04:11

Andy Obusek


1 Answers

I don't think you can replicate the behavior, since sendAsynchronousRequest only calls the completion handler given to it in the code block.

It seems that you must use the delegate method for this purpose. I don't see any benefit from using sendAsynchronousRequest over the normal NSURLConnection, except for the fact that you have to keep an ivar of NSMutableData and possibly NSURLConnection if there are multiple of them per instance of the class.

like image 127
nhahtdh Avatar answered Nov 16 '22 04:11

nhahtdh