【发布时间】:2015-06-14 07:49:06
【问题描述】:
我是 iOS 开发的新手。我有一个项目,我必须使用 WKWebView 而不是 UIWebView。它是一个简单的网页,带有 javascript 到 Objective-C 和其他方式的集成。它工作正常,除非我尝试使用自签名证书打开服务器。在 Safari 上,它会显示一个对话框,我们可以在其中选择继续。但是在我的应用程序中,我无法绕过这一点。
由于某种原因,我必须使用自签名证书运行它。
Delegate 方法 didReceiveAuthenticationChallenge 永远不会被调用。其他委托方法工作正常。我知道 didReceiveAuthenticationChallenge 在 iOS8 中已被贬值,但有人可以告诉我解决方法。由于我是新手,因此非常感谢完整的工作委托方法和/或代码中的任何其他更改。
NSURL *url = [NSURL URLWithString:@"https://mywebsite.com/Default.aspx"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
[[self webView] loadRequest:request];
}
// And the delegate method that is not getting called is
- (void)webView:(WKWebView *)webView
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
CFDataRef exceptions = SecTrustCopyExceptions(serverTrust);
SecTrustSetExceptions(serverTrust, exceptions);
CFRelease(exceptions);
completionHandler(NSURLSessionAuthChallengeUseCredential,
[NSURLCredential credentialForTrust:serverTrust]);
}
【问题讨论】:
-
您是否找到任何解决 didReceiveAuthenticationChallenge 的方法?在我的情况下,它也永远不会被调用。同样,由于它在 iOS8 中已被弃用,我们如何在 iOS8 中实现这一点?
-
我找不到任何解决方案,因此我将服务器上的证书更改为有效证书以消除此错误。
标签: ios objective-c ssl-certificate wkwebview