HypeDitto / iOS-Study

iOS 기술 면접 대비
0 stars 0 forks source link

URLSession에 대해서 설명하시오. #34

Open HeegeePark opened 1 year ago

HeegeePark commented 1 year ago

image

URLSession은 네트워크 통신과 관련된 작업들의 그룹을 관리하는 객체

Foundation 프레임워크에 포함되어 있는 클래스이다.

Overview

YouHojoon commented 1 year ago

동작 순서

  1. URLSessionConfiguration 생성
  2. Session 생성
  3. 사용할 Task 결정, 적절한 Response 메소드 작성
  4. Task 실행
  5. Task 완료 후 Response 메소드 실행

URLSessionConfiguration

세션의 타임아웃 값, 쿠키나 캐시 설정 등을 할 수 있음

URLSession 유형

URLSession.shared() // 기본 요청을 위한 세션, 사용자 정의 불가
URLSession(configuration: .default) // 기본적인 세션, 디스크 기반 캐싱
URLSession(configuration: .ephemral) // 디스크에 어떤 데이터도 저장하지 않고 메모리에 올림, 세션 만료시 관련된 데이터 삭제
URLSession(configuration: .background) // Suspended 상태에서도 업로드 다운로드 가능, 앱이 종료되고 다시시작하면 identifier를 사용해 진행 중이던 전송 상태를 찾을 수 있다.

URLSessionTask

세션 작업을 나타내는 추상 클래스

URLSessionDataTask

URLSessionUploadTask

URLSessionDownloadTask