views:

183

answers:

3

Hi there

I am working on an iPhone app in which I am calling a web service in my app for accomplishing the same I am creating a NSURLConnection the parsing of data is based upon the response of connection delegate's didReceiveResponse: method. I would like to halt the execution of my code until I get any response from my service but I am not sure how to do the same. Please let me know if you have solution.

Thanks Sandy

A: 

Sorry, I don't have the code right in front of me, but there is a blocking NSUrlRequest. Search for blocking/NSURL/iPhone on google / iPhone doc's to get the full answer.

KevinDTimm
+7  A: 

In my opinion what you want to do is not halt the execution of your code (Apple won't be happy about it) but rather alert the user that you're waiting for something and disable your UI for anything you don't want the user to do in the meantime.

You can construct a fairly standard and simple way for this, which go something like this:

  1. Create a UIView with a black background and set it's opacity to 0.8 - This will give users the disabled look. And set the size of the view to cover your entire screen
  2. Add a UIButton with a custom style to fill your UIView - This will disable user clicks by catching them before they get to your other controls
  3. Add a UIActivityIndicatorView and start it.

When you get the didReceiveResponse remove the "wait" view and go about with dealing with the response you got.

Ron Srebro
A: 

Just use NSURLConnection synchronously, do a search for NSURLConnection Synchronous.

Jordan