简体   繁体   English

iOS 8 didReceiveAuthenticationChallenge 没有被调用 WKWebView Objective C

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

I am new to iOS development.我是 iOS 开发的新手。 I have a project where I have to use WKWebView instead of UIWebView.我有一个项目,我必须使用 WKWebView 而不是 UIWebView。 Its a simple webpage with javascript to Objective-C and other way round integration.它是一个简单的网页,带有 javascript 到 Objective-C 和其他方式的集成。 It is working fine except when I try to open a server with self-signed certificate.它工作正常,除非我尝试使用自签名证书打开服务器。 On Safari it shows a dialog box where we can choose to continue.在 Safari 上,它会显示一个对话框,我们可以在其中选择继续。 However on my Application I cannot bypass this.但是在我的应用程序中,我无法绕过它。

For some reason I have to run it with self-signed certificate.出于某种原因,我必须使用自签名证书运行它。

The Delegate method didReceiveAuthenticationChallenge is never called.从不调用委托方法 didReceiveAuthenticationChallenge。 Other delegate methods are working fine.其他委托方法工作正常。 I know didReceiveAuthenticationChallenge is depreciated in iOS8 but can someone please tell me the workaround for this.我知道 didReceiveAuthenticationChallenge 在 iOS8 中已贬值,但有人可以告诉我解决方法。 As I am a newbie so a complete working delegate method and/or any other changes in the code will be highly appreciated.由于我是新手,因此非常感谢完整的工作委托方法和/或代码中的任何其他更改。

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]);

} }

This has been confirmed as a bug by Apple.这已被Apple确认为错误。 It has been fixed in iOS9.它已在 iOS9 中修复。

In the code snippet you posted, i didn't see you were setting the class as the navigationDelegate of the webview..在您发布的代码片段中,我没有看到您将类设置为 webview 的 navigationDelegate ..

Your view controller should implement the protocol WKNavigationDelegate and you need to add the below snippet for the delegate to be invoked..您的视图控制器应该实现协议WKNavigationDelegate并且您需要为要调用的委托添加以下代码段。

[self webView].navigationDelegate = self;

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

相关问题 针对didReceiveAuthenticationChallenge的WKWebView iOS 10.3崩溃? - WKWebView iOS 10.3 crash for didReceiveAuthenticationChallenge? iOS 9 WKWebView在OAuth 2流程上执行了didReceiveAuthenticationChallenge - iOS 9 WKWebView didReceiveAuthenticationChallenge on OAuth 2 flow WKWebView中的iOS Objective-C LocalStore - iOS Objective-C LocalStore in WKWebView 在Objective-C中的WKWebView上评估JavaScript时获取“发生JavaScript异常” - Getting “A JavaScript exception occurred” When evaluateJavaScript on WKWebView in Objective-C ios didReceiveAuthenticationChallenge状态 - ios didReceiveAuthenticationChallenge status iOS / Objective-C:未调用UINavigationBar委托 - iOS/Objective-C: UINavigationBar delegate not called 未调用iOS Objective-C UIBarButtonItem操作 - iOS Objective-C UIBarButtonItem Action Not Called 没有为 iOS 13 调用 didRegisterForRemoteNotificationsWithDeviceToken(目标 C) - didRegisterForRemoteNotificationsWithDeviceToken not called for iOS 13 (Objective C) Objective-c updateSearchResultsForSearchController 没有被调用 - Objective-c updateSearchResultsForSearchController not getting called 目标C-iOS-UIWebView保留在ARC中,但未调用Delegate方法 - Objective C - iOS - UIWebView getting retained in ARC but Delegate methods are not being called
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM