I think this is a bug in AFNetworking 2.0. Here is the implementation:
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler { NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling; __block NSURLCredential *credential = nil; if (self.taskDidReceiveAuthenticationChallenge) { disposition = self.taskDidReceiveAuthenticationChallenge(session, task, challenge, &credential); } else { [self URLSession:session didReceiveChallenge:challenge completionHandler:completionHandler]; return; } if (completionHandler) { completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, credential); } }
Note that even if you specify NSURLSessionAuthChallengeUseCredential , AFNetworking passes back NSURLSessionAuthChallengePerformDefaultHandling , which says: "The default processing for the call is as if this delegate was not implemented, the credential parameter is ignored."
source share