One Logo Pool Ball
Foundation · IOS API REFERENCE

URLSession

class · iOS 7.0+ · SDK 27.1

class URLSession

Members (53)

static · iOS 7.0+ · Deprecated in iOS 13.0

new

TypeScript
static new(): URLSession
Swift declaration
class func new() -> Self
init · iOS 7.0+

init

TypeScript
static initConfiguration(configuration: URLSessionConfiguration): URLSession
Swift declaration
init(configuration: URLSessionConfiguration)
init · iOS 7.0+

init

TypeScript
static initConfigurationDelegateDelegateQueue(configuration: URLSessionConfiguration, delegate?: (Implements<URLSessionDelegate> | SDKHandle) | null, queue?: (OperationQueue) | null): URLSession
Swift declaration
init(configuration: URLSessionConfiguration, delegate: (any URLSessionDelegate)?, delegateQueue queue: OperationQueue?)
get · iOS 7.0+

shared

TypeScript
static get shared(): URLSession
Swift declaration
class var shared: URLSession { get }
method · iOS 7.0+

dataTask

TypeScript
dataTaskWith(request: URLRequest): URLSessionDataTask
Swift declaration
func dataTask(with request: URLRequest) -> URLSessionDataTask
method

dataTask

TypeScript
dataTaskWithCompletionHandler(request: URLRequest, completionHandler: ((arg0: (ArrayBuffer) | null, arg1: (URLResponse) | null, arg2: (NativeError) | null) => void)): URLSessionDataTask
Swift declaration
func dataTask(with request: URLRequest, completionHandler: @escaping @Sendable (Data?, URLResponse?, (any Error)?) -> Void) -> URLSessionDataTask
method · iOS 7.0+

dataTask

TypeScript
dataTaskWith52518(url: string): URLSessionDataTask
Swift declaration
func dataTask(with url: URL) -> URLSessionDataTask
method

dataTask

TypeScript
dataTaskWithCompletionHandler56310(url: string, completionHandler: ((arg0: (ArrayBuffer) | null, arg1: (URLResponse) | null, arg2: (NativeError) | null) => void)): URLSessionDataTask
Swift declaration
func dataTask(with url: URL, completionHandler: @escaping @Sendable (Data?, URLResponse?, (any Error)?) -> Void) -> URLSessionDataTask
method · iOS 7.0+

downloadTask

TypeScript
downloadTaskWith(request: URLRequest): URLSessionDownloadTask
Swift declaration
func downloadTask(with request: URLRequest) -> URLSessionDownloadTask
method

downloadTask

TypeScript
downloadTaskWithCompletionHandler(request: URLRequest, completionHandler: ((arg0: (string) | null, arg1: (URLResponse) | null, arg2: (NativeError) | null) => void)): URLSessionDownloadTask
Swift declaration
func downloadTask(with request: URLRequest, completionHandler: @escaping @Sendable (URL?, URLResponse?, (any Error)?) -> Void) -> URLSessionDownloadTask
method · iOS 7.0+

downloadTask

TypeScript
downloadTaskWithResumeData(resumeData: ArrayBuffer): URLSessionDownloadTask
Swift declaration
func downloadTask(withResumeData resumeData: Data) -> URLSessionDownloadTask
method

downloadTask

TypeScript
downloadTaskWithResumeDataCompletionHandler(resumeData: ArrayBuffer, completionHandler: ((arg0: (string) | null, arg1: (URLResponse) | null, arg2: (NativeError) | null) => void)): URLSessionDownloadTask
Swift declaration
func downloadTask(withResumeData resumeData: Data, completionHandler: @escaping @Sendable (URL?, URLResponse?, (any Error)?) -> Void) -> URLSessionDownloadTask
method · iOS 7.0+

downloadTask

TypeScript
downloadTaskWith32742(url: string): URLSessionDownloadTask
Swift declaration
func downloadTask(with url: URL) -> URLSessionDownloadTask
method

downloadTask

TypeScript
downloadTaskWithCompletionHandler24406(url: string, completionHandler: ((arg0: (string) | null, arg1: (URLResponse) | null, arg2: (NativeError) | null) => void)): URLSessionDownloadTask
Swift declaration
func downloadTask(with url: URL, completionHandler: @escaping @Sendable (URL?, URLResponse?, (any Error)?) -> Void) -> URLSessionDownloadTask
method · iOS 7.0+

finishTasksAndInvalidate

TypeScript
finishTasksAndInvalidate(): void
Swift declaration
func finishTasksAndInvalidate()
method · iOS 7.0+

flush

TypeScript
flush(completionHandler: (() => void)): void
Swift declaration
func flush() async
method · iOS 9.0+

getAllTasks

TypeScript
getAllTasks(completionHandler: ((arg0: Array<URLSessionTask>) => void)): void
Swift declaration
var allTasks: [URLSessionTask] { get async }
method · iOS 7.0+

getTasksWithCompletionHandler

TypeScript
getTasksWithCompletionHandler(completionHandler: ((arg0: Array<URLSessionDataTask>, arg1: Array<URLSessionUploadTask>, arg2: Array<URLSessionDownloadTask>) => void)): void
Swift declaration
var tasks: ([URLSessionDataTask], [URLSessionUploadTask], [URLSessionDownloadTask]) { get async }
init · iOS 7.0+ · Deprecated in iOS 13.0

init

TypeScript
static init(): URLSession
Swift declaration
init()
method · iOS 7.0+

invalidateAndCancel

TypeScript
invalidateAndCancel(): void
Swift declaration
func invalidateAndCancel()
method · iOS 7.0+

reset

TypeScript
reset(completionHandler: (() => void)): void
Swift declaration
func reset() async
method · iOS 9.0+

streamTask

TypeScript
streamTaskWithHostNamePort(hostname: string, port: number): URLSessionStreamTask
Swift declaration
func streamTask(withHostName hostname: String, port: Int) -> URLSessionStreamTask
method · iOS 9.0+ · Deprecated in iOS 100000.0

streamTask

TypeScript
streamTaskWith(service: NetService): URLSessionStreamTask
Swift declaration
func streamTask(with service: NetService) -> URLSessionStreamTask
method · iOS 7.0+

uploadTask

TypeScript
uploadTaskWithFrom(request: URLRequest, bodyData: ArrayBuffer): URLSessionUploadTask
Swift declaration
func uploadTask(with request: URLRequest, from bodyData: Data) -> URLSessionUploadTask
method

uploadTask

TypeScript
uploadTaskWithFromCompletionHandler(request: URLRequest, bodyData: (ArrayBuffer) | null, completionHandler: ((arg0: (ArrayBuffer) | null, arg1: (URLResponse) | null, arg2: (NativeError) | null) => void)): URLSessionUploadTask
Swift declaration
func uploadTask(with request: URLRequest, from bodyData: Data?, completionHandler: @escaping @Sendable (Data?, URLResponse?, (any Error)?) -> Void) -> URLSessionUploadTask
method · iOS 7.0+

uploadTask

TypeScript
uploadTaskWithFromFile(request: URLRequest, fileURL: string): URLSessionUploadTask
Swift declaration
func uploadTask(with request: URLRequest, fromFile fileURL: URL) -> URLSessionUploadTask
method

uploadTask

TypeScript
uploadTaskWithFromFileCompletionHandler(request: URLRequest, fileURL: string, completionHandler: ((arg0: (ArrayBuffer) | null, arg1: (URLResponse) | null, arg2: (NativeError) | null) => void)): URLSessionUploadTask
Swift declaration
func uploadTask(with request: URLRequest, fromFile fileURL: URL, completionHandler: @escaping @Sendable (Data?, URLResponse?, (any Error)?) -> Void) -> URLSessionUploadTask
method · iOS 17.0+

uploadTask

TypeScript
uploadTaskWithResumeData(resumeData: ArrayBuffer): URLSessionUploadTask
Swift declaration
func uploadTask(withResumeData resumeData: Data) -> URLSessionUploadTask
method · iOS 17.0+

uploadTask

TypeScript
uploadTaskWithResumeDataCompletionHandler(resumeData: ArrayBuffer, completionHandler: ((arg0: (ArrayBuffer) | null, arg1: (URLResponse) | null, arg2: (NativeError) | null) => void)): URLSessionUploadTask
Swift declaration
func uploadTask(withResumeData resumeData: Data, completionHandler: @escaping @Sendable (Data?, URLResponse?, (any Error)?) -> Void) -> URLSessionUploadTask
method · iOS 7.0+

uploadTask

TypeScript
uploadTaskWithStreamedRequest(request: URLRequest): URLSessionUploadTask
Swift declaration
func uploadTask(withStreamedRequest request: URLRequest) -> URLSessionUploadTask
method · iOS 13.0+

webSocketTask

TypeScript
webSocketTaskWith(request: URLRequest): URLSessionWebSocketTask
Swift declaration
func webSocketTask(with request: URLRequest) -> URLSessionWebSocketTask
method · iOS 13.0+

webSocketTask

TypeScript
webSocketTaskWith14765(url: string): URLSessionWebSocketTask
Swift declaration
func webSocketTask(with url: URL) -> URLSessionWebSocketTask
method · iOS 13.0+

webSocketTask

TypeScript
webSocketTaskWithProtocols(url: string, protocols: Array<string>): URLSessionWebSocketTask
Swift declaration
func webSocketTask(with url: URL, protocols: [String]) -> URLSessionWebSocketTask
get · iOS 7.0+

configuration

TypeScript
get configuration(): URLSessionConfiguration
Swift declaration
@NSCopying var configuration: URLSessionConfiguration { get }
get · iOS 7.0+

delegate

TypeScript
get delegate(): (SDKHandle) | null
Swift declaration
var delegate: (any URLSessionDelegate)? { get }
get · iOS 7.0+

delegateQueue

TypeScript
get delegateQueue(): OperationQueue
Swift declaration
var delegateQueue: OperationQueue { get }
get · iOS 7.0+

sessionDescription

TypeScript
get sessionDescription(): (string) | null
Swift declaration
var sessionDescription: String? { get set }
set · iOS 7.0+

sessionDescription

TypeScript
set sessionDescription(value: (string) | null)
Swift declaration
var sessionDescription: String? { get set }
method · iOS 13.0+

dataTaskPublisher

TypeScript
dataTaskPublisherFor(request: URLRequest): URLSession_DataTaskPublisher
Swift declaration
func dataTaskPublisher(for request: URLRequest) -> URLSession.DataTaskPublisher

Returns a publisher that wraps a URL session data task for a given URL request. The publisher publishes data when the task completes, or terminates if the task fails with an error. - Parameter request: The URL request for which to create a data task. - Returns: A publisher that wraps a data task for the URL request.

method · iOS 13.0+

dataTaskPublisher

TypeScript
dataTaskPublisherFor33509(url: string): URLSession_DataTaskPublisher
Swift declaration
func dataTaskPublisher(for url: URL) -> URLSession.DataTaskPublisher

Returns a publisher that wraps a URL session data task for a given URL. The publisher publishes data when the task completes, or terminates if the task fails with an error. - Parameter url: The URL for which to create a data task. - Returns: A publisher that wraps a data task for the URL.

method · iOS 15.0+

data

TypeScript
dataForDelegate(request: URLRequest, delegate?: (Implements<URLSessionTaskDelegate> | SDKHandle) | null): Promise<[ArrayBuffer, URLResponse]>
Swift declaration
func data(for request: URLRequest, delegate: (any URLSessionTaskDelegate)? = nil) async throws -> (Data, URLResponse)

Convenience method to load data using a URLRequest, creates and resumes a URLSessionDataTask internally. - Parameter request: The URLRequest for which to load data. - Parameter delegate: Task-specific delegate. - Returns: Data and response.

method · iOS 13.0+

data

TypeScript
dataFor(request: URLRequest): Promise<[ArrayBuffer, URLResponse]>
Swift declaration
func data(for request: URLRequest) async throws -> (Data, URLResponse)

Convenience method to load data using a URLRequest, creates and resumes a URLSessionDataTask internally. - Parameter request: The URLRequest for which to load data. - Returns: Data and response.

method · iOS 15.0+

data

TypeScript
dataFromDelegate(url: string, delegate?: (Implements<URLSessionTaskDelegate> | SDKHandle) | null): Promise<[ArrayBuffer, URLResponse]>
Swift declaration
func data(from url: URL, delegate: (any URLSessionTaskDelegate)? = nil) async throws -> (Data, URLResponse)

Convenience method to load data using a URL, creates and resumes a URLSessionDataTask internally. - Parameter url: The URL for which to load data. - Parameter delegate: Task-specific delegate. - Returns: Data and response.

method · iOS 13.0+

data

TypeScript
dataFrom(url: string): Promise<[ArrayBuffer, URLResponse]>
Swift declaration
func data(from url: URL) async throws -> (Data, URLResponse)

Convenience method to load data using a URL, creates and resumes a URLSessionDataTask internally. - Parameter url: The URL for which to load data. - Returns: Data and response.

method · iOS 15.0+

bytes

TypeScript
bytesForDelegate(request: URLRequest, delegate?: (Implements<URLSessionTaskDelegate> | SDKHandle) | null): Promise<[URLSession_AsyncBytes, URLResponse]>
Swift declaration
func bytes(for request: URLRequest, delegate: (any URLSessionTaskDelegate)? = nil) async throws -> (URLSession.AsyncBytes, URLResponse)

Returns a byte stream that conforms to AsyncSequence protocol. - Parameter request: The URLRequest for which to load data. - Parameter delegate: Task-specific delegate. - Returns: Data stream and response.

method · iOS 15.0+

bytes

TypeScript
bytesFromDelegate(url: string, delegate?: (Implements<URLSessionTaskDelegate> | SDKHandle) | null): Promise<[URLSession_AsyncBytes, URLResponse]>
Swift declaration
func bytes(from url: URL, delegate: (any URLSessionTaskDelegate)? = nil) async throws -> (URLSession.AsyncBytes, URLResponse)

Returns a byte stream that conforms to AsyncSequence protocol. - Parameter url: The URL for which to load data. - Parameter delegate: Task-specific delegate. - Returns: Data stream and response.

method · iOS 15.0+

upload

TypeScript
uploadForFromDelegate(request: URLRequest, bodyData: ArrayBuffer, delegate?: (Implements<URLSessionTaskDelegate> | SDKHandle) | null): Promise<[ArrayBuffer, URLResponse]>
Swift declaration
func upload(for request: URLRequest, from bodyData: Data, delegate: (any URLSessionTaskDelegate)? = nil) async throws -> (Data, URLResponse)

Convenience method to upload data using a URLRequest, creates and resumes a URLSessionUploadTask internally. - Parameter request: The URLRequest for which to upload data. - Parameter bodyData: Data to upload. - Parameter delegate: Task-specific delegate. - Returns: Data and response.

method · iOS 13.0+

upload

TypeScript
uploadForFrom(request: URLRequest, bodyData: ArrayBuffer): Promise<[ArrayBuffer, URLResponse]>
Swift declaration
func upload(for request: URLRequest, from bodyData: Data) async throws -> (Data, URLResponse)

Convenience method to upload data using a URLRequest, creates and resumes a URLSessionUploadTask internally. - Parameter request: The URLRequest for which to upload data. - Parameter bodyData: Data to upload. - Returns: Data and response.

method · iOS 15.0+

upload

TypeScript
uploadForFromFileDelegate(request: URLRequest, fileURL: string, delegate?: (Implements<URLSessionTaskDelegate> | SDKHandle) | null): Promise<[ArrayBuffer, URLResponse]>
Swift declaration
func upload(for request: URLRequest, fromFile fileURL: URL, delegate: (any URLSessionTaskDelegate)? = nil) async throws -> (Data, URLResponse)

Convenience method to upload data using a URLRequest, creates and resumes a URLSessionUploadTask internally. - Parameter request: The URLRequest for which to upload data. - Parameter fileURL: File to upload. - Parameter delegate: Task-specific delegate. - Returns: Data and response.

method · iOS 13.0+

upload

TypeScript
uploadForFromFile(request: URLRequest, fileURL: string): Promise<[ArrayBuffer, URLResponse]>
Swift declaration
func upload(for request: URLRequest, fromFile fileURL: URL) async throws -> (Data, URLResponse)

Convenience method to upload data using a URLRequest, creates and resumes a URLSessionUploadTask internally. - Parameter request: The URLRequest for which to upload data. - Parameter fileURL: File to upload. - Returns: Data and response.

method · iOS 15.0+

download

TypeScript
downloadResumeFromDelegate(resumeData: ArrayBuffer, delegate?: (Implements<URLSessionTaskDelegate> | SDKHandle) | null): Promise<[string, URLResponse]>
Swift declaration
func download(resumeFrom resumeData: Data, delegate: (any URLSessionTaskDelegate)? = nil) async throws -> (URL, URLResponse)

Convenience method to resume download, creates and resumes a URLSessionDownloadTask internally. - Parameter resumeData: Resume data from an incomplete download. - Parameter delegate: Task-specific delegate. - Returns: Downloaded file URL and response. The file will not be removed automatically.

method · iOS 15.0+

download

TypeScript
downloadForDelegate(request: URLRequest, delegate?: (Implements<URLSessionTaskDelegate> | SDKHandle) | null): Promise<[string, URLResponse]>
Swift declaration
func download(for request: URLRequest, delegate: (any URLSessionTaskDelegate)? = nil) async throws -> (URL, URLResponse)

Convenience method to download using a URLRequest, creates and resumes a URLSessionDownloadTask internally. - Parameter request: The URLRequest for which to download. - Parameter delegate: Task-specific delegate. - Returns: Downloaded file URL and response. The file will not be removed automatically.

method · iOS 15.0+

download

TypeScript
downloadFromDelegate(url: string, delegate?: (Implements<URLSessionTaskDelegate> | SDKHandle) | null): Promise<[string, URLResponse]>
Swift declaration
func download(from url: URL, delegate: (any URLSessionTaskDelegate)? = nil) async throws -> (URL, URLResponse)

Convenience method to download using a URL, creates and resumes a URLSessionDownloadTask internally. - Parameter url: The URL for which to download. - Parameter delegate: Task-specific delegate. - Returns: Downloaded file URL and response. The file will not be removed automatically.

Skipped declarations

No declarations were skipped in this snapshot.

All Foundation types →