ASIHTTPRequest, EXC_BAD_ACCESS when the request is completed

I am trying to execute an asynchronous request with ASIHTTPRequest, but some problems get notified when the request is executed.

-(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?

+3
source share
3 answers

Are you sure your class that implements - (void)requestFinished:(ASIHTTPRequest *)requeststill exists when the request ends? It seems to me that the class is being freed too soon. Note that the property delegatedoes not retain its content.

[self retain] doDownload [self release] - (void)requestFinished:(ASIHTTPRequest *)request, , (!), [self release] . , . .

NSZombieEnabled, YES, .

+7

.

[request setDidFinishSelector:@selector(requestFinished)];

requestFinished (ASIHTTPRequest *).
":" , , .

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

[request responseString];

Before this call, check that the request is on hold. In simplified terms, it is equal to zero :) If this is the case, you should not forget to save it when you create it in the doDownload method.

0
source

Source: https://habr.com/ru/post/1730584/


All Articles