gpt4 book ai didi

ios - WKWebView - 组件失败时不调用 didFailProvisionalNavigation

转载 作者:行者123 更新时间:2023-12-02 10:40:28 68 4
gpt4 key购买 nike

我试图在 WKWebView 中加载页面组件时记录错误失败,但 didFailProvisionalNavigation不叫。

我删除了 CSS 文件从我的页面进行测试,但没有结果。

当我在谷歌浏览器上加载页面时,我可以找到丢失的文件

enter image description here

WKWebView 初始化为:

@interface MyWebView : UIViewController <WKNavigationDelegate>
@property(strong,nonatomic) WKWebView *loginWebView;
@end

.m 文件
@implementation MyWebView

- (void) initWebView {

// Set and Load the WebView
self.webView = [[WKWebView alloc] initWithFrame:self.view.frame];
self.webView.navigationDelegate = self;
[self.webView loadRequest:request];
[self.view addSubview:self.webView];
}

然后我实现了以下方法:
webView:decidePolicyForNavigationAction:decisionHandler:
webView:didStartProvisionalNavigation:
webView:didFinishNavigation:
webView:didFailNavigation:withError:
webView:didFailProvisionalNavigation:withError:

前三个方法被调用,但都没有调用 didFailNavigation也不是 didFailProvisionalNavigation被称为

通过查看 documentation对于 didFailProvisionalNavigation我们有

Called when an error occurs while the web view is loading content.



好吧,内容失败(css文件)并且没有调用该方法,我该怎么做?

PS:我也试过使用 UIWebView !

最佳答案

- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{
NSInteger statusCode = ((NSHTTPURLResponse *)navigationResponse.response).statusCode;
NSLog(@"statusCode:%ld", statusCode);
if (statusCode/100 == 4 || statusCode/100 == 5) {
NSLog(@"webview error:%@", navigationResponse.response);
}
decisionHandler(WKNavigationResponsePolicyAllow);
}

这行得通!

关于ios - WKWebView - 组件失败时不调用 didFailProvisionalNavigation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41163722/

68 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com