Ignoring NSURLErrorDomain error -999 does not work in UIWebView(忽略 NSURLErrorDomain 错误 -999 在 UIWebView 中不起作用)
问题描述
我试图避免在 UIWebView
的委托返回这样的错误时产生的问题.我的委托实现中有常见的解决方法(我在 Internet 的任何地方都看到过)
I'm trying to avoid the problem generated while UIWebView
's delegate returns an error like that. I have the common workaround (I saw it anywhere in the Internet) in my delegate implementation
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
if ([error code] == NSURLErrorCancelled) return;
}
我遇到的问题是这并不总是有效.有时会加载网页,有时会加载网页的某些部分(标题、文本的一部分……),有时不会加载任何内容.
The problem I have is that this does not works always. Sometimes loads the web, another times loads parts of the web (the header, a part of the text...) and several times does not load anything.
还有其他解决方案吗?是否存在任何可以正常工作的浏览器的开源实现?
Is there any other solution to this? Exists any open source implementation of a browser that works properly?
推荐答案
来自 Apple 文档:
From Apple docs:
NSURLErrorCancelled (-999)
NSURLErrorCancelled (-999)
" 取消异步加载时返回.Web Kit 框架委托在对加载资源执行取消操作时将收到此错误.请注意,如果下载被取消,NSURLConnection 或 NSURLDownload 委托将不会收到此错误."
"Returned when an asynchronous load is canceled. A Web Kit framework delegate will receive this error when it performs a cancel operation on a loading resource. Note that an NSURLConnection or NSURLDownload delegate will not receive this error if the download is canceled."
因此,最有可能发生这种情况的情况是,在第一个请求完成之前,您先加载一个请求,然后再加载另一个请求(或同一个请求).这可能发生.例如,如果您在像 viewDidAppear:
这样可以多次调用的方法中调用 loadRequest
(或 loadHTMLString
).如果您快速点击 UIWebView
中的 2 个链接,也会发生这种情况.
So, the most likely case for this to happen is for you to load a request and then another one (or the same one), before the first one is completed. This can happen. e.g., if you call loadRequest
(or loadHTMLString
) in a method like viewDidAppear:
that can be called multiple times. This has also been reported to happen if you quickly tap 2 links in the UIWebView
.
因此,一般建议是查看您调用 loadRequest
(或 loadHTMLString
)的方式和位置,并可能提供一些代码.
So, the general suggestion is to review how and where you call loadRequest
(or loadHTMLString
), and possibly provide some code.
为了解决这个问题,我建议将以下跟踪添加到您的 Web 视图委托:
In order to troubleshoot this, I would suggest to add the following traces to your web view delegate:
- (void)webViewDidStartLoad:(UIWebView *)webView {
NSLog(@"Starting to download request: %@", [webView.request.URL absoluteString]);
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(@"Finished downloading request: %@", [webView.request.URL absoluteString]);
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
if ([error code] == NSURLErrorCancelled)
NSLog(@"Canceled request: %@", [webView.request.URL absoluteString]);
}
如果您检查输出,您应该更清楚地看到发生了什么.如果您粘贴输出,我们可以尝试进一步帮助您.
If you inspect the output, you should see more clearly what is going on. If you paste the output, we could try and help you further.
这篇关于忽略 NSURLErrorDomain 错误 -999 在 UIWebView 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:忽略 NSURLErrorDomain 错误 -999 在 UIWebView 中不起作用
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01