Reputation: 4081
I want to display data loaded from a webservice but the webservice is taking a long time and the "data" is being displayed before it is loaded. How may I force it to wait?
Thanks.
Connection to web service
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:tmpURl];
[theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:@"http://tempuri.org/GetCategory" forHTTPHeaderField:@"SOAPAction"];
NSString *msgLength=[NSString stringWithFormat:@"%i",[soapMessage length]];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(conn)
{
}
Upvotes: 0
Views: 476
Reputation: 2492
The NSURLConnection
class is asynchronous by default, there's nothing in particular that you have to do to. I can see from the code snipped you've posted above that you are setting the delegate of the NSURLConnection
, you just have to implement the methods required by the delegate.
Have a look at the NSURLConnection
class reference, particularly the "Overview" section, where the delegate methods are explained.
In your code snippet, after you start the connection, you can display an UIAlertView with a spinner for example, and dismiss it then in the delegate method when your data has arrived.
Upvotes: 2
Reputation: 39916
There are two ways to do it, web service soap calls can be invoked asynchronously and synchronously, but I will only recommend using asynchronous method as you are using now because it is faster, you will unnecessarily block iPhone UI thread and you may block the UI so user will think your program has crashed.
The best thing will be to show some UI animation and some MODAL window over the desktop that will prevent user from entering any input.
Upvotes: 1