我正在开发一款iPhone应用程序.在开发期间,我需要连接到使用自签名SSL证书的服务器.我很确定- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler我有机会编写一些异常代码来实现这一点.但是,我找不到任何资源告诉我如何做到这一点.我可以在日志中看到以下错误:
NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
Run Code Online (Sandbox Code Playgroud)
除此之外,当我NSLog(@"error = %@", error);从上面的委托方法中得到:
错误域= NSURLErrorDomain代码= -1202"此服务器的证书无效.您可能正在连接到假装为"api.mydevelopmenturl.com"的服务器,这可能会使您的机密信息面临风险." UserInfo = 0x10cbdbcf0 {NSUnderlyingError = 0x112ec9730"此服务器的证书无效.您可能正在连接到假装为"api.mydevelopmenturl.com"的服务器,这可能会使您的机密信息面临风险.",NSErrorFailingURLStringKey = https: //api.mydevelopmenturl.com/posts,NSErrorFailingURLKey = https://api.mydevelopmenturl.com/posts,NSLocalizedRecoverySuggestion =您是否还要连接到服务器?,NSURLErrorFailingURLPeerTrustErrorKey =,NSLocalizedDescription =此服务器的证书无效.您可能正在连接到假装为"api.mydevelopmenturl.com"的服务器,这可能会使您的机密信息面临风险.}
有关如何解决此问题的任何想法?请在我阅读概念文档时发布代码,但我不理解它们.这是一个超越我的例子:https://developer.apple.com/library/content/technotes/tn2232/_index.html