ASIHTTPRequest,EXC_BAD_ACCESS请求完成后 [英] ASIHTTPRequest, EXC_BAD_ACCESS when request did finished

查看:194
本文介绍了ASIHTTPRequest,EXC_BAD_ACCESS请求完成后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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 *)请求仍然在请求完成时?看起来像我的班级得到释放太​​早。请注意,委托属性不保留其内容。

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.

您可以添加 [自我保留] to doDownload [self release] to - (void)requestFinished :( ASIHTTPRequest *)请求,但请确保(!) [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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆