EventMonitor

public protocol EventMonitor : Sendable

Protocol outlining the lifetime events inside Alamofire. It includes both events received from the various URLSession delegate protocols as well as various events from the lifetime of Request and its subclasses.

  • queue Default implementation

    The DispatchQueue onto which Alamofire’s root CompositeEventMonitor will dispatch events. .main by default.

    Default Implementation

    The default queue on which CompositeEventMonitors will call the EventMonitor methods. .main by default.

    Declaration

    Swift

    var queue: DispatchQueue { get }

URLSessionDelegate Events

  • Event called during URLSessionDelegate‘s urlSession(_:didBecomeInvalidWithError:) method.

    Default Implementation

    Declaration

    Swift

    func urlSession(_ session: URLSession, didBecomeInvalidWithError error: (any Error)?)

URLSessionTaskDelegate Events

  • urlSession(_:task:didReceive:) Default implementation

    Event called during URLSessionTaskDelegate‘s urlSession(_:task:didReceive:completionHandler:) method.

    Default Implementation

    Declaration

    Swift

    func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge)
  • Event called during URLSessionTaskDelegate‘s urlSession(_:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:) method.

    Default Implementation

    Declaration

    Swift

    func urlSession(_ session: URLSession,
                    task: URLSessionTask,
                    didSendBodyData bytesSent: Int64,
                    totalBytesSent: Int64,
                    totalBytesExpectedToSend: Int64)
  • urlSession(_:taskNeedsNewBodyStream:) Default implementation

    Event called during URLSessionTaskDelegate‘s urlSession(_:task:needNewBodyStream:) method.

    Default Implementation

    Declaration

    Swift

    func urlSession(_ session: URLSession, taskNeedsNewBodyStream task: URLSessionTask)
  • Event called during URLSessionTaskDelegate‘s urlSession(_:task:willPerformHTTPRedirection:newRequest:completionHandler:) method.

    Default Implementation

    Declaration

    Swift

    func urlSession(_ session: URLSession,
                    task: URLSessionTask,
                    willPerformHTTPRedirection response: HTTPURLResponse,
                    newRequest request: URLRequest)
  • Event called during URLSessionTaskDelegate‘s urlSession(_:task:didFinishCollecting:) method.

    Default Implementation

    Declaration

    Swift

    func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics)
  • Event called during URLSessionTaskDelegate‘s urlSession(_:task:didCompleteWithError:) method.

    Default Implementation

    Declaration

    Swift

    func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: (any Error)?)
  • Event called during URLSessionTaskDelegate‘s urlSession(_:taskIsWaitingForConnectivity:) method.

    Default Implementation

    Declaration

    Swift

    func urlSession(_ session: URLSession, taskIsWaitingForConnectivity task: URLSessionTask)

URLSessionDataDelegate Events

  • urlSession(_:dataTask:didReceive:) Default implementation

    Event called during URLSessionDataDelegate‘s urlSession(_:dataTask:didReceive:completionHandler:) method.

    Default Implementation

    Undocumented

    Declaration

    Swift

    func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse)
  • Event called during URLSessionDataDelegate‘s urlSession(_:dataTask:didReceive:) method.

    Declaration

    Swift

    func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data)
  • Event called during URLSessionDataDelegate‘s urlSession(_:dataTask:willCacheResponse:completionHandler:) method.

    Default Implementation

    Declaration

    Swift

    func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, willCacheResponse proposedResponse: CachedURLResponse)

URLSessionDownloadDelegate Events

  • Event called during URLSessionDownloadDelegate‘s urlSession(_:downloadTask:didResumeAtOffset:expectedTotalBytes:) method.

    Default Implementation

    Declaration

    Swift

    func urlSession(_ session: URLSession,
                    downloadTask: URLSessionDownloadTask,
                    didResumeAtOffset fileOffset: Int64,
                    expectedTotalBytes: Int64)
  • Event called during URLSessionDownloadDelegate‘s urlSession(_:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:) method.

    Default Implementation

    Declaration

    Swift

    func urlSession(_ session: URLSession,
                    downloadTask: URLSessionDownloadTask,
                    didWriteData bytesWritten: Int64,
                    totalBytesWritten: Int64,
                    totalBytesExpectedToWrite: Int64)
  • Event called during URLSessionDownloadDelegate‘s urlSession(_:downloadTask:didFinishDownloadingTo:) method.

    Default Implementation

    Declaration

    Swift

    func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL)

Request Events

  • Event called when a URLRequest is first created for a Request. If a RequestAdapter is active, the URLRequest will be adapted before being issued.

    Default Implementation

    Declaration

    Swift

    func request(_ request: Request, didCreateInitialURLRequest urlRequest: URLRequest)
  • Event called when the attempt to create a URLRequest from a Request‘s original URLRequestConvertible value fails.

    Default Implementation

    Declaration

    Swift

    func request(_ request: Request, didFailToCreateURLRequestWithError error: AFError)
  • request(_:didAdaptInitialRequest:to:) Default implementation

    Event called when a RequestAdapter adapts the Request‘s initial URLRequest.

    Default Implementation

    Declaration

    Swift

    func request(_ request: Request, didAdaptInitialRequest initialRequest: URLRequest, to adaptedRequest: URLRequest)
  • Event called when a RequestAdapter fails to adapt the Request‘s initial URLRequest.

    Default Implementation

    Declaration

    Swift

    func request(_ request: Request, didFailToAdaptURLRequest initialRequest: URLRequest, withError error: AFError)
  • request(_:didCreateURLRequest:) Default implementation

    Event called when a final URLRequest is created for a Request.

    Default Implementation

    Declaration

    Swift

    func request(_ request: Request, didCreateURLRequest urlRequest: URLRequest)
  • request(_:didCreateTask:) Default implementation

    Event called when a URLSessionTask subclass instance is created for a Request.

    Default Implementation

    Declaration

    Swift

    func request(_ request: Request, didCreateTask task: URLSessionTask)
  • request(_:didGatherMetrics:) Default implementation

    Event called when a Request receives a URLSessionTaskMetrics value.

    Default Implementation

    Declaration

    Swift

    func request(_ request: Request, didGatherMetrics metrics: URLSessionTaskMetrics)
  • Event called when a Request fails due to an error created by Alamofire. e.g. When certificate pinning fails.

    Default Implementation

    Declaration

    Swift

    func request(_ request: Request, didFailTask task: URLSessionTask, earlyWithError error: AFError)
  • request(_:didCompleteTask:with:) Default implementation

    Event called when a Request‘s task completes, possibly with an error. A Request may receive this event multiple times if it is retried.

    Default Implementation

    Declaration

    Swift

    func request(_ request: Request, didCompleteTask task: URLSessionTask, with error: AFError?)
  • requestIsRetrying(_:) Default implementation

    Event called when a Request is about to be retried.

    Default Implementation

    Declaration

    Swift

    func requestIsRetrying(_ request: Request)
  • requestDidFinish(_:) Default implementation

    Event called when a Request finishes and response serializers are being called.

    Default Implementation

    Declaration

    Swift

    func requestDidFinish(_ request: Request)
  • requestDidResume(_:) Default implementation

    Event called when a Request receives a resume call.

    Default Implementation

    Declaration

    Swift

    func requestDidResume(_ request: Request)
  • request(_:didResumeTask:) Default implementation

    Event called when a Request‘s associated URLSessionTask is resumed.

    Default Implementation

    Declaration

    Swift

    func request(_ request: Request, didResumeTask task: URLSessionTask)
  • requestDidSuspend(_:) Default implementation

    Event called when a Request receives a suspend call.

    Default Implementation

    Declaration

    Swift

    func requestDidSuspend(_ request: Request)
  • request(_:didSuspendTask:) Default implementation

    Event called when a Request‘s associated URLSessionTask is suspended.

    Default Implementation

    Declaration

    Swift

    func request(_ request: Request, didSuspendTask task: URLSessionTask)
  • requestDidCancel(_:) Default implementation

    Event called when a Request receives a cancel call.

    Default Implementation

    Declaration

    Swift

    func requestDidCancel(_ request: Request)
  • request(_:didCancelTask:) Default implementation

    Event called when a Request‘s associated URLSessionTask is cancelled.

    Default Implementation

    Declaration

    Swift

    func request(_ request: Request, didCancelTask task: URLSessionTask)

DataRequest Events

DataStreamRequest Events

UploadRequest Events

DownloadRequest Events