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: