开发者

Stopping/ aborting a NSURLConnection

开发者 https://www.devze.com 2023-04-10 02:55 出处:网络
I would like to know how I can stop/abort a NSURLConnection while it is performing it load request. The reason I would like to know is that, I am parsing an XML using NSURLConnection and sometimes th

I would like to know how I can stop/abort a NSURLConnection while it is performing it load request.

The reason I would like to know is that, I am parsing an XML using NSURLConnection and sometimes the time taken to get a response is too long.

here is my code to make things clearer...

I am parsing an XML using NSXMLParser and loading the req with my soap message before I request it using NSURLConnection

conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
    if (conn) 
    {
        webData = [[NSMutableData data] retain];
    }

}

The following piece of code is what is standard

-(void) connection:(NSURLConnection *) connection 
didReceiveResponse:(NSURLResponse *) response 
{
    [webData setLength: 0];
}


-(void) connection:(NSURLConnection *) connection 
    didReceiveData:(NSData *) data 
{
    [webData appendData:data];
}

In this, sometimes the time taken for the program to get to connection didReceiveData is too long and the user would need to abort that operation.

So I would like to know if this is possible.

I know how to abor开发者_StackOverflow中文版t after it starts parsing by using [parser abort] but I dont know how to abort the NSURLConnection.

It would be great if someone could help me out with this.


Use [conn cancel]; to stop an ongoing download.

0

精彩评论

暂无评论...
验证码 换一张
取 消