Common function for Calling webservice objective-C.

 When you start writing applications for IOS (I-Phone), Communication with a Web server is a very crucial phase. You need to call web-services many times to get and post data from the server, As we all know here we have two methods to call web-services in IOS “GET” and  “POST”. Frequently POST method is used to implement the web-services.

So I come up with a solution for calling web-services. Sometimes it becomes very hesitating to call web API in each view controller. According to Apple documentation, NSurlConnection is deprecated after IOS 7. NSurlSession is an alternative class that we can use. NsurlSession is more efficient, flexible than NSurlConnection. NSurlSession has better-caching capability for maintaining global as well as local session caching. You can create a singleton class as well for calling web service and write this method so that a single instance can be created, Need not make multiple objects of that class.

Benefits of using NSurlSession than NSurlConnection:
1)  NSurlSession provides background upload and downloads task configuration it makes more flexible to communicate with the web server.
2) NSurlSession supports Global catching.
3) NSurlSession has better session configuration ability than NSurlConnection.
4)  NSurlSession  Can able to resume and stop communication with the web server.
5) Speed and concurrency of NSurlSession are better than  NSurlConnection.

Insert the below function into your .m file.

And implement the function when you require.

You will receive a response in the dictionary. if you have any question please ask. Happy coding. Please comment and share the article if you find something useful.

5 thoughts on “Common function for Calling webservice objective-C.”

  1. Your approach is not right to make a common method for Webservices, this will block your main thread as you are calling synchronous method to get data, instead of synchronous use asynchronous methods.

  2. using synchronous or asynchronous methodology depends on the how you are going to implement this web service,if you are using synchronous methodology fetch the dictionary data inside it.


    //fetch your contents which comes from web service.



Leave a Comment