I have implemented custom protocol with session delegate as below -
- (void)startLoading
{
NSMutableURLRequest *mReq = [self.request mutableCopy];
NSURL *url = [[self request] URL];
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
//...
//...
if(!_mySession) {
_mySession = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:[NSOperationQueue mainQueue]];
}
//task creation here
}
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler{
NSURLAuthenticationChallenge* challengeWrapper = [[NSURLAuthenticationChallenge alloc] initWithAuthenticationChallenge:challenge sender:[[CustomAuthChallengeWrappers alloc] initWithSessionCompletionHandler:completionHandler]];
if(self.client){
if([self.client respondsToSelector:@selector(URLProtocol:didReceiveAuthenticationChallenge:)]) {
NSLog("auth-challenge");
[self.client URLProtocol:self didReceiveAuthenticationChallenge:challengeWrapper];
}
}
}
If client uses NSURLConnection, it is working fine. If I use NSURLSession on client side, its forwarding the Auth challenge but not receiving back in custom protocol. Challenge wrapper is implemented as per this link: http://stackoverflow.com/questions/27604052/nsurlsessiontask-authentication-challenge-completionhandler-and-nsurlauthenticat
Am I missing anything for NSURLSession?
Its not working with xcode 7.3.1 with latest iOS 9.3. It was working with previous versions.