Skip to content

Instantly share code, notes, and snippets.

@willyliu
Last active December 30, 2015 18:19
Show Gist options
  • Save willyliu/7867219 to your computer and use it in GitHub Desktop.
Save willyliu/7867219 to your computer and use it in GitHub Desktop.
Ignores SSL certificate checking.
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler
{
NSURLProtectionSpace * protectionSpace = challenge.protectionSpace;
if ([protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
SecTrustRef serverTrust = protectionSpace.serverTrust;
completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust: serverTrust]);
}
else {
completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment