Contents

urlSession(_:task:willBeginDelayedRequest:completionHandler:)

Tells the delegate that a delayed URL session task will now begin loading.

Declaration

optional func urlSession(_ session: URLSession, task: URLSessionTask, willBeginDelayedRequest request: URLRequest, completionHandler: @escaping  @Sendable (URLSession.DelayedRequestDisposition, URLRequest?) -> Void)
optional func urlSession(_ session: URLSession, task: URLSessionTask, willBeginDelayedRequest request: URLRequest) async -> (URLSession.DelayedRequestDisposition, URLRequest?)

Parameters

  • session:

    The session containing the delayed request.

  • task:

    The task handling the delayed request.

  • request:

    The request that was delayed.

  • completionHandler:

    A completion handler to perform the request. The completion handler takes two parameters: a disposition that tells the task how to proceed, and a new request object that is only used if the disposition is Usenewrequest.

Discussion

This method is called when a background session task with a delayed start time (as set with the earliestBeginDate property) is ready to start. This delegate method should only be implemented if the request might become stale while waiting for the network load and needs to be replaced by a new request.

For loading to continue, the delegate must call the completion handler, passing in a disposition that indicates how the task should proceed. Passing the URLSession.DelayedRequestDisposition.cancel disposition is equivalent to calling cancel() on the task directly.

See Also

Handling delayed and waiting tasks