English 中文(简体)
ASIHTTPRequest, EXC_BAD_ACCESS when request did finished
原标题:

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 is never called. I get an exception in ASIHTTPRequest.m, -handleStreamCompleted:

if (fileError) {
    [self failWithError:fileError];
} else {
    [self requestFinished];   <----- this call fails
}

Any clues?

最佳回答

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.

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.

You might also try to debug with NSZombieEnabled set to YES to find the error.

问题回答

Following line of your code seems to be wrong.

[request setDidFinishSelector:@selector(requestFinished)];

requestFinished method has an argument (ASIHTTPRequest *).
Therefore you should add ":", when you set a selector like as follows.

[request setDidFinishSelector:@selector(requestFinished:)];

[request responseString];

Check retainCount of request before this call. Propably it equals zero :) If that - you shouldn t forget to retain it when you creates it in doDownload method.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签