During the development process, there may be some cases where HTTPS requests fail to display the web page or HTTPS images in the web page
The solution
1. Inplist
The file will beAllow Arbitrary Loads
in Web Content
Set toYES
If you have setNSAllowsArbitraryLoads
为 YES
, do not set above
2. Add proxy method to wkWebView
// Load untrusted HTTPS
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^) (NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler{
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
NSURLCredential *card = [[NSURLCredential alloc]initWithTrust:challenge.protectionSpace.serverTrust];
completionHandler(NSURLSessionAuthChallengeUseCredential,card); }}Copy the code