I am using NSURLSession dataTaskWithRequest:completionHandler:to execute some requests on my server. I use a self-signed certificate, so when the calling delegate URLSession:didReceiveChallenge:completionHandler:is called, I can perform my internal checks to make sure everything is in order.
All of this works great on the first request I submit. After the completion handler is called with NSURLSessionAuthChallengeUseCredential, then the following requests never call URLSession:didReceiveChallenge:completionHandler:.
For reasons that I will not enter this post, I would really like to be URLSession:didReceiveChallenge:completionHandler:called every time so that I can perform my own check. I assume that NSURLSession somehow caches the certificate and stores it in some list of "valid certificates", so it does not perform this check every time. I want to clear this cache in order to do my own check every time. If I restart the application, it URLSession:didReceiveChallenge:completionHandler:is called again.
I tried to set credential storage to zero without success:
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
configuration.URLCredentialStorage = nil;
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
[[session dataTaskWithRequest:request
completionHandler:^(NSData *data,
NSURLResponse *response,
NSError *error) {
...
}] resume];
Any ideas how to do this?
Thank!
source
share