Instance Method

URLSession:task:didReceiveChallenge:completionHandler:

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

Declaration

- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler;

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 NSURLSessionDelegate protocol also provides a session-level authentication delegate method. The method called depends on the type of authentication challenge:

See Also

Delegate Methods

URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:

Periodically informs the delegate of the progress of sending body content to the server.

URLSession:task:needNewBodyStream:

Tells the delegate when a task requires a new request body stream to send to the remote server.

URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:

Tells the delegate that the remote server requested an HTTP redirect.

URLSession:task:didFinishCollectingMetrics:

Tells the delegate that the session finished collecting metrics for the task.

NSURLSessionTaskMetrics

An NSURLSessionTaskMetrics object encapsulates the metrics for a session task. Each object contains the taskInterval and redirectCount, as well as metrics for each request / response transaction made during the execution of the task.

URLSession:task:didCompleteWithError:

Tells the delegate that the task finished transferring data.