I want help making multiple web service calls on the same view controller. Is there a way I can do it.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are several ways to solve this problem and each depends on your circumstance. The first would be to use multiple copies of
+ (id)stringWithContentsOfURL:(NSURL *)url encoding:(NSStringEncoding)enc error:(NSError **)errormethod of NSString. So if you wanted to get the contents of some URL you could use the following codeThe issue with this approach is that it will block whatever thread you call that on. So you can either call it in a thread or use one of the other approaches.
The second approach is to use NSURLConnection. This uses delegates to handle the process in an event driven fashion. There is a good summary of that approach here. But you will also need to differentiate between requests in the delegate methods. For example
The third approach is to use some kind of wrapper class that handles http requests at a higher level. Personally I like ASIHTTPRequest. It can handle requests synchronous, asynchronous using delegates, and asynchronous using blocks.
This example shows you how to do an asynchronous request using blocks as the callbacks intsead of delegate methods. Note that this can only be used in iOS 4.0 and greater since it uses blocks. But ASIHTTPRequest in general can be used on iOS 3.0 and greater without blocks.