I have a instance of ASINetworkQueue, and I added instances of ASIHTTPRequest to the queue; meanwhile I have delegate methods set for the Queue as well as each requests:
[submittingReportQueue setDelegate:self];
[submittingReportQueue setRequestDidFailSelector:@selector(submitReportQueueWentWrong:)];
[submittingReportQueue setQueueDidFinishSelector:@selector(submitReportQueueFinished:)];
and in a loop I added request to the Queue, add call [submittingReportQueue go] outside of the loop.
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
NSString *auth = [[AuthenticationManager sharedInstance] authenticationHeaderValue];
request addRequestHeader:@"Authorization" value:auth];
[request addRequestHeader:@"Content-Type" value:@"application/json"];
NSString *jsonString =[self jsonStringForExpenseReport:report];
[request appendPostData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
[request setDelegate:self];
[request setUserInfo:[NSDictionary dictionaryWithObject:report forKey:@"Report"]];
[request setDidFailSelector:@selector(submitReportRequestWentWrong:)];
[request setDidReceiveDataSelector:@selector(submitReportRequestDone:)];
[requests addObject:request];
[submittingReportQueue addOperation:request];
Following are my delegate methods:
- (void)submitReportQueueWentWrong:(ASINetworkQueue *)queue
{
NSLog(@"Submit Report WentWRong");
//
- (void)submitReportQueueFinished:(ASINetworkQueue *)queue
{
NSLog(@"Submit Report QueueFinished");
}
//
- (void)submitReportRequestWentWrong:(ASIHTTPRequest *)request
{
NSLog(@"Submit Report Queue went wrong");
}
//
- (void)submitReportRequestDone:(ASIHTTPRequest *)request
{//do work here}
However ASIHTTPRequest.m throws exception in following block of code:
// Does the delegate want to handle the data manually?
if ([[self delegate] respondsToSelector:[self didReceiveDataSelector]]) {
NSMethodSignature *signature = [[[self delegate] class]
instanceMethodSignatureForSelector:[self didReceiveDataSelector]];
NSInvocation *invocation = [[NSInvocation invocationWithMethodSignature:signature]
retain];
[invocation setSelector:[self didReceiveDataSelector]];
[invocation setArgument:&self atIndex:2];
NSData *data = [NSData dataWithBytes:buffer length:bytesRead];
[invocation setArgument:&data atIndex:3];
[invocation retainArguments];
[self performSelectorOnMainThread:@selector(invocateDelegate:) withObject:invocation waitUntilDone:[NSThread isMainThread]];
[invocation setArgument:&data atIndex:3]; throws exception, Error message is 'NSInvalidArgumentException', reason: '* -[NSInvocation setArgument:atIndex:]: index (3) out of bounds [-1, 2]'
What did I do wrong?
Thanks `