ASIHTTPRequest, EXC_BAD_ACCESS 当请求完成时 [英] ASIHTTPRequest, EXC_BAD_ACCESS when request did finished
问题描述
我正在尝试使用 ASIHTTPRequest 执行异步请求,但在请求完成时收到通知时遇到一些问题.
I'm trying to do an asynchronous request with ASIHTTPRequest, but have some problem getting notified when the request is done.
-(void)doDownload{
NSURL *url = [NSURL URLWithString:@"http://www.someurl.com/?"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"someValue" forKey:@"someField"];
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestFinished)];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
}
requestFinished 永远不会被调用.我在 ASIHTTPRequest.m,-handleStreamCompleted 中得到一个异常:
requestFinished is never called. I get an exception in ASIHTTPRequest.m, -handleStreamCompleted:
if (fileError) {
[self failWithError:fileError];
} else {
[self requestFinished]; <----- this call fails
}
有什么线索吗?
推荐答案
你确定你的实现 - (void)requestFinished:(ASIHTTPRequest *)request
的类在请求完成时还在那里?在我看来,该类过早地被解除分配.请注意,delegate
属性不保留其内容.
Are you sure that your class that implements - (void)requestFinished:(ASIHTTPRequest *)request
is still there when the request finishes? It looks to me like the class gets deallocated too early. Note that the delegate
property does not retain its content.
您可以在 doDownload
中添加一个 [self retain]
,在 - (void)requestFinished 中添加一个
,但要确保 (!) [self release]
:(ASIHTTPRequest *)request[self release]
不会被频繁调用.如果请求永远不会完成,这也可能是内存泄漏.最好把你的课留在别处.
You could add a [self retain]
to doDownload
and a [self release]
to - (void)requestFinished:(ASIHTTPRequest *)request
, but make sure (!) that [self release]
doesn't get called too often. This is also a possible memory leak if a request would never finish. It would be best to retain your class somewhere else.
您也可以尝试将 NSZombieEnabled
设置为 YES
进行调试以查找错误.
You might also try to debug with NSZombieEnabled
set to YES
to find the error.
这篇关于ASIHTTPRequest, EXC_BAD_ACCESS 当请求完成时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!