ASIHTTP使用块,因未捕获的异常而终止

时间:2014-05-01 08:05:08

标签: ios ios7 request asihttprequest unrecognized-selector

我在旧的iOS 7项目中使用ASIHTTP。所以今天我将我的文件更新为ASIHTTP的新版本,并尝试使用http://allseeing-i.com/ASIHTTPRequest/How-to-use上的示例中显示的使用块。我的代码如下所示:

NSURL *url = [NSURL URLWithString:@"URL To A Site That Returns A JSON String"];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request addRequestHeader:@"Accept" value:@"application/json"]; //Returneres som JSON
[request setRequestMethod:@"POST"];
[request setCompletionBlock:^{
    // Use when fetching text data
    NSString *responseString = [request responseString];

    // Use when fetching binary data
    NSData *responseData = [request responseData];
}];
[request setFailedBlock:^{
    NSError *error = [request error];
}];
[request startAsynchronous];

运行代码时,我得到以下异常:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ASIHTTPRequest setFailedBlock:]: unrecognized selector sent to instance 0x157529f0'
*** First throw call stack:
(0x2f17bf0b 0x39912ce7 0x2f17f837 0x2f17e137 0x2f0cd098 0x1262fd 0x125957 0x111fcf 0x319afa53 0x319af811 0x31ad758b 0x31ad741f 0x31ad72f7 0xe1c63 0x31ac97f3 0x31b7bcb3 0x31a2ae09 0x319a3b57 0x2f147039 0x2f1449c7 0x2f144d13 0x2f0af769 0x2f0af54b 0x3401c6d3 0x31a0e891 0xb147d 0x39e10ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException

请注意,如果我执行同步调用它可以工作:但我需要这个调用是异步的。

非常感谢任何帮助解决这个问题。

0 个答案:

没有答案