NSURLSession不使用自定义协议的验证挑战



我已经实现了自定义协议与会话委托如下-

- (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]];
}
.....
}
- (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:)]) {
                 debugLog("auth-challenge");
                 [self.client URLProtocol:self didReceiveAuthenticationChallenge:challengeWrapper];
            }
    }
}

如果客户端使用NSURLConnection,它工作正常。如果我在客户端使用NSURLSession,它会转发Auth挑战,但不会在自定义协议中接收回。挑战包装器是按照这个链接实现的:NSURLProtocol Challenge包装器

我是否错过了NSURLSession的任何内容?

只是为了更新它在iOS 10和xcode 8测试版上运行良好。看来iOS 9.3出现了一些问题,在这次发布中已经修复了。

最新更新