開發(fā)過程中會(huì)遇見某些情況在https的請(qǐng)求下網(wǎng)頁或者網(wǎng)頁內(nèi)的https圖片無法正常顯示
解決辦法
1.在plist
文件內(nèi)將Allow Arbitrary Loads
in Web Content
置為 YES
若有設(shè)置NSAllowsArbitraryLoads
為 YES
,可不用設(shè)置上面
NSAllowsArbitraryLoads
2.加入wkWebView的代理方法
//加載不受信任的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);
}
}