我如何知道页面何时无法在 UIWebView 中加载而不是“已停止”? 由用户?
我的应用程序中有一个 UIWebView,我用它来提供网页浏览功能。
我的工具栏上有一个调用
-(void)stopLoading;
UIWebView 的按钮。 这样做的问题是,当此方法发送到 Web 视图时,委托会收到消息
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;
。 此调用伴随的错误是:操作无法完成。 (NSURLErrorDomain 错误 -999。)
我还使用 didFailLoad 消息来判断页面是否确实无法加载 - 在这种情况下,我会向用户显示一条 html 格式的消息,以向他们传达此失败。
所以问题是,如果用户点击停止按钮,则会显示错误页面,而不是仅显示停止之前加载的页面的任何部分。
我曾希望 NSError.h 包含一个我可以比较的错误代码枚举 - 但似乎我必须根据我对日志中出现的错误代码的观察来制作自己的错误代码 - 这小于理想的,因为它们将来可能会改变......
任何建议都会很棒,谢谢。
I have a UIWebView within my application which I'm using to provide web browsing functionality.
I have a button on my toolbar which calls
-(void)stopLoading;
on the UIWebView. The problem with this is that when this method is sent to the web view, the delegate receives the
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;
message. The error accompanying this call is: Operation could not be completed. (NSURLErrorDomain error -999.)
I also use the didFailLoad message to tell if the page actually failed to load - and in that case, I display an html formatted message to user to communicate this failure to them.
So the problem is that if the user hits the stop button, the error page is shown instead of just showing whatever parts of the page loaded before being stopped.
I had hoped that NSError.h contained an enum of error codes that I could compare against - but it seems like I'll have to make my own based on my observations of the error codes that come out in my logs - which is less than ideal, since they could change in the future...
Any suggestions would be great, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能找到解决此问题的最佳方法是使用 webView 给出的错误代码创建一个枚举。
看起来他们不会改变,但如果他们改变了,那么——呵呵。
所以现在,在我的加载失败方法中,我只需将错误对象中的错误代码与我的枚举进行比较,我就可以看到发生了什么 - 看起来有点像这样:
The best way I could find to solve this was to create an enum using the error codes given by the webView.
It doesn't look like they're going to change, but if they do, well - ho hum.
So now, in my failed-to-load method I simply compare the error code from the error object with my enum, and I can see what happened - looks kinda like this:
这些错误代码在 Foundation.framework 的 NSURLError.h 中定义
Those error codes are defined in NSURLError.h, in the Foundation.framework