即使页面稍后加载,也会使用UIWebView调用didFailLoadWithError [英] didFailLoadWithError is called with UIWebView even though page later loads

查看:76
本文介绍了即使页面稍后加载,也会使用UIWebView调用didFailLoadWithError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIViewController,它是一个UIWebViewDelegate,里面有一个UIWebView。我正在尝试加载特定的URL

I have a UIViewController which is a UIWebViewDelegate and has a UIWebView inside of it. I am trying to load a particular URL

    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];
    [self.view addSubview:webView];
    [webView release];

didFailLoadWithError 委托方法几乎是即时的调用,错误对象是:

But the didFailLoadWithErrordelegate method is almost instantly called, and the error object is:

Did fail load with error: Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0x1a66c0 {NSErrorFailingURLKey=www.somewebsite.com, NSErrorFailingURLStringKey=www.somewebsite.com}

然而在不久之后,您可以看到网站加载得很好。

However a short time after, you can see that the website loads just fine.

为什么要调用fail方法?而且无论网站是否真的失败,我怎么知道实际失败的时间与调用方法的时间有关?

Why is the fail method being called? And how do I know when it has actually failed versus when the method was called regardless of if the website actually failed or not?

推荐答案

当页面立即通过javascript或其他方式重定向时,您可以收到此错误

You can get this error when the page is instantly redirected via javascript or somehow else

您可以通过此处的答案来避免显示错误:如何在iPhone 3.0操作系统中修复NSURLErrorDomain错误-999

You can avoid showing the error by answer from here: How do I fix NSURLErrorDomain error -999 in iPhone 3.0 OS

喜欢

if ([error code] != NSURLErrorCancelled) { //show error alert, etc. }

但我不知道如何识别它被调用了。

but I don't know how to recognize where it was invoked.

这篇关于即使页面稍后加载,也会使用UIWebView调用didFailLoadWithError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆