Instance Method

urlSession(_:task:didReceive:completionHandler:)

Requests credentials from the delegate in response to an authentication request from the remote server.

Declaration

optional func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void)

Parameters

session

The session containing the task whose request requires authentication.

task

The task whose request requires authentication.

challenge

An object that contains the request for authentication.

completionHandler

A handler that your delegate method must call. Its parameters are:

  • disposition—One of several constants that describes how the challenge should be handled.

  • credential—The credential that should be used for authentication if disposition is NSURLSessionAuthChallengeUseCredential; otherwise, NULL.

Discussion

This method handles task-level authentication challenges. The URLSessionDelegate protocol also provides a session-level authentication delegate method. The method called depends on the type of authentication challenge:

See Also

Handling Authentication Challenges

enum URLSession.AuthChallengeDisposition

Constants passed by session or task delegates to the provided continuation block in response to an authentication challenge.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software