WKWebView does not load https URL?

前端 未结 6 553
予麋鹿
予麋鹿 2021-02-07 00:16

I have a WKWebView which should load the following url:

https://buchung.salonmeister.de/place/#offer-details-page?id=907599&venueId=301655

6条回答
  •  情书的邮戳
    2021-02-07 01:16

    I had a similar problem with a site that was also protected with a high security TLS 1.2 certificate. To get the WKWebView to accept the server's certificate, I added this code to my web view controller delegate:

    -(void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
    {
        if ([[[challenge protectionSpace]authenticationMethod] isEqualToString: @"NSURLAuthenticationMethodServerTrust"]) {
            SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
            CFDataRef exceptions = SecTrustCopyExceptions(serverTrust);
            SecTrustSetExceptions(serverTrust, exceptions);
            CFRelease(exceptions);
            newCredential = [NSURLCredential credentialForTrust:serverTrust];
            completionHandler(NSURLSessionAuthChallengeUseCredential, newCredential);
        } else {
            completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, newCredential);
        }
    }
    

提交回复
热议问题