Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSURLSession or NSURLConnection - iOS 6 support

I need to make a connection to my server to get some JSON data and I have to support both iOS 6 and iOS 7.

Should I create two classes? One with NSURLSession for iOS 7 and one with NSURLConnection for iOS 6? Or should I just use NSURLConnection for both of them?

like image 772
yoeriboven Avatar asked Oct 16 '13 14:10

yoeriboven


People also ask

What is difference between NSURLConnection and NSURLSession?

An NSURLConnection object handles a single request and any follow-on requests. An NSURLSession object manages multiple tasks, each of which represents a single URL request and any follow-on requests. With NSURLConnection, each connection object has a separate delegate.

What is NSURLSession how is it used?

The NSURLSession class and related classes provide an API for downloading data from and uploading data to endpoints indicated by URLs. Your app can also use this API to perform background downloads when your app isn't running or, in iOS, while your app is suspended.

What is NSURLConnection?

An NSURLConnection object lets you load the contents of a URL by providing a URL request object. The interface for NSURLConnection is sparse, providing only the controls to start and cancel asynchronous loads of a URL request. You perform most of your configuration on the URL request object itself.

What is Nsurl WebSocket?

NSURLSessionWebSocketTask is a concrete subclass of NSURLSessionTask that provides a message-oriented transport protocol over TCP and TLS in the form of WebSocket framing. It follows the WebSocket Protocol defined in RFC 6455. You create a NSURLSessionWebSocketTask with either a ws: or wss: URL.


1 Answers

What benefit would you gain by creating two separate classes that do essentially the same thing? If you can't use NSURLSession because it's only supported in iOS 7, and you can get the same functionality using NSURLConnection, which works in both, then just use NSURLConnection. You will have less code to maintain.

like image 127
Brian Avatar answered Dec 02 '22 12:12

Brian