SessionDelegate
open class SessionDelegate: NSObject
Responsible for handling all delegate callbacks for the underlying session.
-
Access the task delegate for the specified task in a thread-safe manner.
Declaration
Swift
open subscript(task: URLSessionTask) -> Request? -
Overrides default behavior for URLSessionDelegate method
urlSession(_:didBecomeInvalidWithError:).Declaration
Swift
@objc open var sessionDidBecomeInvalidWithError: ((URLSession, Error?) -> Void)? -
Overrides default behavior for URLSessionDelegate method
urlSession(_:didReceive:completionHandler:).Declaration
Swift
open var sessionDidReceiveChallenge: ((URLSession, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))? -
Overrides all behavior for URLSessionDelegate method
urlSession(_:didReceive:completionHandler:)and requires the caller to call thecompletionHandler.Declaration
Swift
@objc open var sessionDidReceiveChallengeWithCompletion: ((URLSession, URLAuthenticationChallenge, (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void)? -
Overrides default behavior for URLSessionDelegate method
urlSessionDidFinishEvents(forBackgroundURLSession:).Declaration
Swift
@objc open var sessionDidFinishEventsForBackgroundURLSession: ((URLSession) -> Void)?
-
Overrides default behavior for URLSessionTaskDelegate method
urlSession(_:task:willPerformHTTPRedirection:newRequest:completionHandler:).Declaration
Swift
@objc open var taskWillPerformHTTPRedirection: ((URLSession, URLSessionTask, HTTPURLResponse, URLRequest) -> URLRequest?)? -
Overrides all behavior for URLSessionTaskDelegate method
urlSession(_:task:willPerformHTTPRedirection:newRequest:completionHandler:)and requires the caller to call thecompletionHandler.Declaration
Swift
@objc open var taskWillPerformHTTPRedirectionWithCompletion: ((URLSession, URLSessionTask, HTTPURLResponse, URLRequest, (URLRequest?) -> Void) -> Void)? -
Overrides default behavior for URLSessionTaskDelegate method
urlSession(_:task:didReceive:completionHandler:).Declaration
Swift
open var taskDidReceiveChallenge: ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))? -
Overrides all behavior for URLSessionTaskDelegate method
urlSession(_:task:didReceive:completionHandler:)and requires the caller to call thecompletionHandler.Declaration
Swift
@objc open var taskDidReceiveChallengeWithCompletion: ((URLSession, URLSessionTask, URLAuthenticationChallenge, (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void)? -
Overrides default behavior for URLSessionTaskDelegate method
urlSession(_:task:needNewBodyStream:).Declaration
Swift
@objc open var taskNeedNewBodyStream: ((URLSession, URLSessionTask) -> InputStream?)? -
Overrides all behavior for URLSessionTaskDelegate method
urlSession(_:task:needNewBodyStream:)and requires the caller to call thecompletionHandler.Declaration
Swift
@objc open var taskNeedNewBodyStreamWithCompletion: ((URLSession, URLSessionTask, (InputStream?) -> Void) -> Void)? -
Overrides default behavior for URLSessionTaskDelegate method
urlSession(_:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:).Declaration
Swift
@objc open var taskDidSendBodyData: ((URLSession, URLSessionTask, Int64, Int64, Int64) -> Void)? -
Overrides default behavior for URLSessionTaskDelegate method
urlSession(_:task:didCompleteWithError:).Declaration
Swift
@objc open var taskDidComplete: ((URLSession, URLSessionTask, Error?) -> Void)?
-
Overrides default behavior for URLSessionDataDelegate method
urlSession(_:dataTask:didReceive:completionHandler:).Declaration
Swift
@objc open var dataTaskDidReceiveResponse: ((URLSession, URLSessionDataTask, URLResponse) -> URLSession.ResponseDisposition)? -
Overrides all behavior for URLSessionDataDelegate method
urlSession(_:dataTask:didReceive:completionHandler:)and requires caller to call thecompletionHandler.Declaration
Swift
@objc open var dataTaskDidReceiveResponseWithCompletion: ((URLSession, URLSessionDataTask, URLResponse, (URLSession.ResponseDisposition) -> Void) -> Void)? -
Overrides default behavior for URLSessionDataDelegate method
urlSession(_:dataTask:didBecome:).Declaration
Swift
@objc open var dataTaskDidBecomeDownloadTask: ((URLSession, URLSessionDataTask, URLSessionDownloadTask) -> Void)? -
Overrides default behavior for URLSessionDataDelegate method
urlSession(_:dataTask:didReceive:).Declaration
Swift
@objc open var dataTaskDidReceiveData: ((URLSession, URLSessionDataTask, Data) -> Void)? -
Overrides default behavior for URLSessionDataDelegate method
urlSession(_:dataTask:willCacheResponse:completionHandler:).Declaration
Swift
@objc open var dataTaskWillCacheResponse: ((URLSession, URLSessionDataTask, CachedURLResponse) -> CachedURLResponse?)? -
Overrides all behavior for URLSessionDataDelegate method
urlSession(_:dataTask:willCacheResponse:completionHandler:)and requires caller to call thecompletionHandler.Declaration
Swift
@objc open var dataTaskWillCacheResponseWithCompletion: ((URLSession, URLSessionDataTask, CachedURLResponse, (CachedURLResponse?) -> Void) -> Void)?
-
Overrides default behavior for URLSessionDownloadDelegate method
urlSession(_:downloadTask:didFinishDownloadingTo:).Declaration
Swift
@objc open var downloadTaskDidFinishDownloadingToURL: ((URLSession, URLSessionDownloadTask, URL) -> Void)? -
Overrides default behavior for URLSessionDownloadDelegate method
urlSession(_:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:).Declaration
Swift
@objc open var downloadTaskDidWriteData: ((URLSession, URLSessionDownloadTask, Int64, Int64, Int64) -> Void)? -
Overrides default behavior for URLSessionDownloadDelegate method
urlSession(_:downloadTask:didResumeAtOffset:expectedTotalBytes:).Declaration
Swift
@objc open var downloadTaskDidResumeAtOffset: ((URLSession, URLSessionDownloadTask, Int64, Int64) -> Void)?
-
Initializes the
SessionDelegateinstance.Declaration
Swift
public override init()
-
Returns a
Boolindicating whether theSessionDelegateimplements or inherits a method that can respond to a specified message.Declaration
Swift
open override func responds(to selector: Selector) -> Bool
-
Tells the delegate that the session has been invalidated.
Declaration
Swift
open func urlSession(_ session: URLSession, didBecomeInvalidWithError error: Error?) -
Requests credentials from the delegate in response to a session-level authentication request from the remote server.
Declaration
Swift
open func urlSession( _ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -
Tells the delegate that all messages enqueued for a session have been delivered.
Declaration
Swift
open func urlSessionDidFinishEvents(forBackgroundURLSession session: URLSession)
-
Tells the delegate that the remote server requested an HTTP redirect.
Declaration
Swift
open func urlSession( _ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void) -
Requests credentials from the delegate in response to an authentication request from the remote server.
Declaration
Swift
open func urlSession( _ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -
Tells the delegate when a task requires a new request body stream to send to the remote server.
Declaration
Swift
open func urlSession( _ session: URLSession, task: URLSessionTask, needNewBodyStream completionHandler: @escaping (InputStream?) -> Void) -
Periodically informs the delegate of the progress of sending body content to the server.
Declaration
Swift
open func urlSession( _ session: URLSession, task: URLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) -
Tells the delegate that the session finished collecting metrics for the task.
Declaration
Swift
open func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) -
Tells the delegate that the task finished transferring data.
Declaration
Swift
open func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?)
-
Tells the delegate that the data task received the initial reply (headers) from the server.
Declaration
Swift
open func urlSession( _ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) -
Tells the delegate that the data task was changed to a download task.
Declaration
Swift
open func urlSession( _ session: URLSession, dataTask: URLSessionDataTask, didBecome downloadTask: URLSessionDownloadTask) -
Tells the delegate that the data task has received some of the expected data.
Declaration
Swift
open func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) -
Asks the delegate whether the data (or upload) task should store the response in the cache.
Declaration
Swift
open func urlSession( _ session: URLSession, dataTask: URLSessionDataTask, willCacheResponse proposedResponse: CachedURLResponse, completionHandler: @escaping (CachedURLResponse?) -> Void)
-
Tells the delegate that a download task has finished downloading.
Declaration
Swift
open func urlSession( _ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) -
Periodically informs the delegate about the download’s progress.
Declaration
Swift
open func urlSession( _ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) -
Tells the delegate that the download task has resumed downloading.
Declaration
Swift
open func urlSession( _ session: URLSession, downloadTask: URLSessionDownloadTask, didResumeAtOffset fileOffset: Int64, expectedTotalBytes: Int64)
View on GitHub
SessionDelegate Class Reference