开发者

How to Stop a Synchronous NSURLRequest in iPhone?

开发者 https://www.devze.com 2023-01-12 05:54 出处:网络
I used synchronous request to fetch data from server and insert those data in the database.This is working perfectly alright.Now the problem is that I want to stop the request in between the process i

I used synchronous request to fetch data from server and insert those data in the database.This is working perfectly alright.Now the problem is that I want to stop the request in between the process is going on (means when the request is already send for data or during when the data are inserting in the database).So Is there any way that we can stop the Synchronous request forcefully.What is the best way to do that?Please suggest... Below is the code for that

NSURL *url = [NSURL URLWithString:soapMessage];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];

[theRequest addValue: @"application/x-www-form-urlencoded" forHTTPHeaderF开发者_运维问答ield:@"Content-Type"];
[theRequest setHTTPMethod:@"GET"];

NSData *theData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse: nil error:nil];


NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData: theData];
[xmlParser setDelegate: self];
[xmlParser setShouldResolveExternalEntities: YES];
[xmlParser parse];
[xmlParser release];

and after that performed simple insert operation.


the only way to stop a synchronous request is to kill the thread it is on. (hence the term synchronous).

0

精彩评论

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