如何在iOS中修复“TIC SSL Trust Error”?

当我尝试使用Web服务登录应用程序时。 我还设置了我的plist-file ,如下所示

在此处输入图像描述

我收到以下错误。 我的控制台上显示此错误

 TIC SSL Trust Error [5:0x1c017fbc0]: 3:0 NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802) Task . HTTP load failed (error code: -1200 [3:-9802] 

以下代码适用于我。 我实现了NSURLSessionDelegate的委托方法(didReceiveChallenge)

 NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration delegate:self delegateQueue:Nil]; NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error){ //Handle the response }]; [task resume]; 

// NSURLSessionDelegate方法

 - (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler{ if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){ if([challenge.protectionSpace.host isEqualToString:@"yourdomain.com"]){ NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]; completionHandler(NSURLSessionAuthChallengeUseCredential,credential); } 

}}

苹果开发者文档指南。

ssl更改iOS 11 https://forums.developer.apple.com/thread/80197

证书查看器还具有更具体的消息传递。 在下面的屏幕截图中,您可以看到针对特定信任错误显示警告。 在这种情况下,错误显示“此证书无法validation(弱摘要算法)”,因为它是使用SHA-1签名的。

在某些情况下,连接到服务器并发出命令以进行测试非常有用。 对于典型的Internet协议(HTTP,SMTP,NNTP等),您可以使用telnet工具执行此操作。 但是,如果协议使用TLS,则不起作用。 在这种情况下,最好的选择是openssl工具的s_client子命令。 清单1显示了如何使用此工具手动获取内容(请记住HTTPS使用端口443)。

清单1使用openssl s_client

 $ openssl s_client -connect www.apple.com:443 CONNECTED(00000003) [...] GET / HTTP/1.1 Host: www.apple.com HTTP/1.1 200 OK Server: Apache/2.2.3 (Oracle) Content-Length: 9464 Content-Type: text/html; charset=UTF-8 ntCoent-Length: 9516 Cache-Control: max-age=47 Expires: Mon, 25 Jun 2012 16:18:24 GMT Date: Mon, 25 Jun 2012 16:17:37 GMT Connection: keep-alive   [...]  closed $ 

s_client子命令支持许多有用的调试选项。 例如:

您可以提供-cert参数以使其响应客户端证书请求。 您可以指定-showcerts选项以获取服务器提供的完整证书列表。 -debug和-msg选项启用低级调试function。 有关这些选项的更多信息,请参见手册页。