繁体   English   中英

iOS 8 didReceiveAuthenticationChallenge 没有被调用 WKWebView Objective C

[英]iOS 8 didReceiveAuthenticationChallenge not getting called for WKWebView Objective C

我是 iOS 开发的新手。 我有一个项目,我必须使用 WKWebView 而不是 UIWebView。 它是一个简单的网页,带有 javascript 到 Objective-C 和其他方式的集成。 它工作正常,除非我尝试使用自签名证书打开服务器。 在 Safari 上,它会显示一个对话框,我们可以在其中选择继续。 但是在我的应用程序中,我无法绕过它。

出于某种原因,我必须使用自签名证书运行它。

从不调用委托方法 didReceiveAuthenticationChallenge。 其他委托方法工作正常。 我知道 didReceiveAuthenticationChallenge 在 iOS8 中已贬值,但有人可以告诉我解决方法。 由于我是新手,因此非常感谢完整的工作委托方法和/或代码中的任何其他更改。

NSURL *url = [NSURL URLWithString:@"https://mywebsite.com/Default.aspx"];

NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];

[[self webView] loadRequest:request];

}

// And the delegate method that is not getting called is 
- (void)webView:(WKWebView *)webView
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
    SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
    CFDataRef exceptions = SecTrustCopyExceptions(serverTrust);
    SecTrustSetExceptions(serverTrust, exceptions);
    CFRelease(exceptions);

completionHandler(NSURLSessionAuthChallengeUseCredential,
                  [NSURLCredential credentialForTrust:serverTrust]);

}

这已被Apple确认为错误。 它已在 iOS9 中修复。

在您发布的代码片段中,我没有看到您将类设置为 webview 的 navigationDelegate ..

您的视图控制器应该实现协议WKNavigationDelegate并且您需要为要调用的委托添加以下代码段。

[self webView].navigationDelegate = self;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM