Pul*_*ull 6 certificate uiwebview ios ios8 wkwebview
这是我用来允许证书的代码:
@interface NSURLRequest(DummyInterface)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host;
+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host;
@end
@implementation NSURLRequest(DummyInterface)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
return [host isEqualToString:@"mysite.com"];
}
@end
Run Code Online (Sandbox Code Playgroud)
我初始化我的WKWebView:
NSURL *urlReq = [NSURL URLWithString:@"mysite.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:urlReq];
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[urlReq host]];
WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
mainWebView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:theConfiguration];
[mainWebView setNavigationDelegate:self];
[mainWebView loadRequest:request];
Run Code Online (Sandbox Code Playgroud)
它适用于http网站,但我使用https有这个错误:
此服务器的证书无效.您可能正在连接到假装为"mysite.com"的服务器,这可能会使您的机密信息面临风险.
当我使用UIWebView并实现"canAuthenticateAgainstProtectionSpace"功能时,它正在工作,但现在我不明白我必须做什么.
我错过了什么或WKWebView无法处理HTTPS?
尝试这个,为我工作
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
NSLog(@"Allowing all");
SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
CFDataRef exceptions = SecTrustCopyExceptions (serverTrust);
SecTrustSetExceptions (serverTrust, exceptions);
CFRelease (exceptions);
completionHandler (NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:serverTrust]);
}
Run Code Online (Sandbox Code Playgroud)
并且不要忘记添加到Info.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Run Code Online (Sandbox Code Playgroud)
小智 1
不确定问题是什么,但有报告称 WKWebView 存在 SSL 问题: https://code.google.com/p/chromium/issues/detail ?id=423444#c3
| 归档时间: |
|
| 查看次数: |
4026 次 |
| 最近记录: |