自己証明書を使ったローカルサーバーにWKWebViewでアクセスすると、
Would you like to connect to the server anyway?
The certificate for this server is invalid.
というダイアログが表示され、ログには
WebPageProxy::didFailProvisionalLoadForFrame: frameID = 3, domain = NSURLErrorDomain, code = -1202
と出力された。
自己証明書を使ったローカルサーバーにWKWebViewでアクセスするために、以下のようにした。
WKWebView* webView = [[WKWebView alloc] initWithFrame:bounds configuration:webConfig];
webView.navigationDelegate = self;
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
{
NSURLCredential* credential = [[NSURLCredential alloc] initWithTrust:[challenge protectionSpace].serverTrust];
completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
}