URLSession Class 공식문서를 읽고 몇가지 프로퍼티에 대해 알아봅니다.
An object that coordinates a group of related, network data transfer tasks.
네트워크 데이터 전송 관련된 그룹을 조정하는 개체입니다.
class URLSession: NSObject
URLSession 클래스는 NSObject를 상속한 클래스 개체입니다.
URLSession클래스나 관련 클래스는 URL로 표시되어있는 Endpoint에서 데이터를 다운로드/업로드 하기 위한 API를 제공합니다.
앱이 실행중이 아니거나, iOS에서 앱이 suspended된 동안 백그라운드에서 다운로드를 수행하기 위해 URLSession관련 API를 사용할 수 있습니다.
추가적으로, URLSessionDelegate와 URLSessionTaskDelegate는 authentication을 지원하고 redirection이나 task completion같은 이벤트를 수신 할 수 있습니다.
URLSession 인스턴스를 생성합니다.data-transfer관련 task그룹을 조정합니다.window당 하나의 세션을 만듭니다.URL에 대한 요청을 나타내는 작업을 추가합니다.Types of URL Sessions
The tasks within a given URL session share a common session configuration object, which defines connection behavior, like the maximum number of simultaneous connections to make to a single host, whether connections can use the cellular network, and so on.
URLSession has a singleton shared session (which doesn’t have a configuration object) for basic requests. It’s not as customizable as sessions you create, but it serves as a good starting point if you have very limited requirements. You access this session by calling the shared class method. For other kinds of sessions, you create a URLSession with one of three kinds of configurations:
- A default session behaves much like the shared session, but lets you configure it. You can also assign a delegate to the default session to obtain data incrementally.
- Ephemeral sessions are similar to shared sessions, but don’t write caches, cookies, or credentials to disk.
- Background sessions let you perform uploads and downloads of content in the background while your app isn’t running.
See Creating a Session Configuration Object in the URLSessionConfiguration class for details on creating each type of configuration.
공식 문서 내용은 위와 같습니다.
요약을 간단하게 해봅시다.
URLSession에는 basic requests를 위한 공유세션이 있습니다.shared 클래스 메소드를 호출해서 세션에 접근합니다.configuration을 사용해서 URLSession을 생성합니다.default session은 shared session과 유사하게 동작합니다.configure가능합니다.incrementally로 가져 올 수도 있습니다.Ephemeral session은 shared session과 유사하지만 캐시, 쿠키 또는 자격 증명에 사용되지는 않습니다.Background session을 사용하면 앱이 실행되지 않는 백그라운드 상태에서 Contents Upload & Download 작업을 수행 할 수 있습니다.Within a session, you create tasks that optionally upload data to a server and then retrieve data from the server either as a file on disk or as one or more NSData objects in memory. The URLSession API provides four types of tasks:
- Data tasks send and receive data using NSData objects. Data tasks are intended for short, often interactive requests to a server.
- Upload tasks are similar to data tasks, but they also send data (often in the form of a file), and support background uploads while the app isn’t running.
- Download tasks retrieve data in the form of a file, and support background downloads and uploads while the app isn’t running.
WebSocket tasks exchange messages over TCP and TLS, using the WebSocket protocol defined in RFC 6455.
Task는 정의된 웹소켓 프로토콜을 사용해서 TCP / TLS를 통해서 메세지를 교환합니다.