WKWebView 证书认证

-(void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
{
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {

    NSURLCredential *card = [[NSURLCredential alloc]initWithTrust:challenge.protectionSpace.serverTrust];
    
    completionHandler(NSURLSessionAuthChallengeUseCredential,card);
}

// if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
// if ([challenge previousFailureCount] == 0) {
// NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
// completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
// } else {
// completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
// }
// } else {
// completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
// }
}

http://blog.csdn.net/aajunwang/article/details/51008526

你可能感兴趣的:(WKWebView 证书认证)