我有一个 ASINetworkQueue 实例,并将 ASIHTTPRequest 实例添加到队列中;同时,我为队列以及每个请求设置了委托方法:
[submittingReportQueue setDelegate:self];
[submittingReportQueue setRequestDidFailSelector:@selector(submitReportQueueWentWrong:)];
[submittingReportQueue setQueueDidFinishSelector:@selector(submitReportQueueFinished:)];
在一个循环中,我向队列添加了请求,在循环之外添加了调用 [submittingReportQueue go]。
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];
以下是我的委托方法:
- (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}
但是 ASIHTTPRequest.m 在以下代码块中抛出异常:
// 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]];
[调用 setArgument:&data atIndex:3]; 抛出异常,错误消息是 'NSInvalidArgumentException',原因:'*** -[NSInvocation setArgument:atIndex:]: index (3) out of bounds [-1, 2]'
我做错了什么?
谢谢`