tags:

views:

38

answers:

2

Hi,

I am making a synchronous request to the web service and unable to show the loading... alert. As I am unable to access UI while synchoronous request.

Can you anybody please guide me to show the activity indicator whle I am making synchoronous request.

Is it possible to show the loading message if run the synchronous request in background thread.

Regards, Malleswar

A: 

I would recommend running the request in a background thread. I always use the ASIHTTPRequest library for making async requests. In the callback methods you can than put code to toggle the loading alert visibility.

WardB
Thanks for the quick reply. But I already started with NSData * data = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:(its in different class method) and calling this method from UIthread directly. I cant change at this point. Can you please guide me to call that method in background thread and show activity indicator while request is running.
+1  A: 

Hi Malleswar, yes it is possible to do this.

you should never block the main thread of an application with a UI as you've described -- always consider this in your designs.

there are a few approaches to accomplish this. NSOperation is a good starting point. so you'll create an NSOperation subclass which will perform the request, then notify something that the request has finished, and provide the prepared data.

1) start your progress indicator

2) add the operation

3) stop the indicator once the (NSOperation to controller) transaction has completed. hint: use performSelectorOnMainThread:… from the operation.

Justin
Thanks for yo the detailed description. Can y ou pelase provide me some code or sample download to implement this.
You can do without subclassing NSOperation. Just use `performSelectorInBackground`. This will automatically spawn a new thread.
Rengers