【问题标题】:iOS 8 didReceiveAuthenticationChallenge not getting called for WKWebView Objective CiOS 8 didReceiveAuthenticationChallenge 没有被 WKWebView Objective C 调用
【发布时间】:2015-06-14 07:49:06
【问题描述】:

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

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

Delegate 方法 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]);

}

【问题讨论】:

  • 您是否找到任何解决 didReceiveAuthenticationChallenge 的方法?在我的情况下,它也永远不会被调用。同样,由于它在 iOS8 中已被弃用,我们如何在 iOS8 中实现这一点?
  • 我找不到任何解决方案,因此我将服务器上的证书更改为有效证书以消除此错误。

标签: ios objective-c ssl-certificate wkwebview


【解决方案1】:

Apple 已确认这是一个错误。它已在 iOS9 中修复。

【讨论】:

  • 能否请您添加确认修复的参考资料?
  • @Phani 我向 Apple 提交了一个错误,现在已修复。不幸的是,其他用户无法看到 Apple 的错误报告。我已经在我的项目中验证了修复,它在 iOS 9.0 (XCode 7.0) 中可以正常工作。很抱歉我不能在这里分享我的项目,但是这个场景很容易用一个简单的 WKWebView 和原始问题中的代码来测试。
【解决方案2】:

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

你的视图控制器应该实现协议WKNavigationDelegate,你需要添加下面的sn-p来调用委托..

[self webView].navigationDelegate = self;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-21
    相关资源
    最近更新 更多