Here is the code I use to resolve the certificate:
@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
And I initialize my WKWebView as follows:
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];
It works fine for an http site, but I have this error using https:
The certificate for this server is not valid. You might be connecting to a server that pretends to be "mysite.com" that could put your sensitive information at risk.
It worked when I used UIWebView and implemented the function "canAuthenticateAgainstProtectionSpace", but now I donβt understand what I need to do.
Am I missing something or can WKWebView not handle HTTPS?
source share