即使页面稍后加载,也会使用UIWebView调用didFailLoadWithError

Cod*_*Guy 10 iphone xcode uiwebview ipad

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

    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];
    [self.view addSubview:webView];
    [webView release];
Run Code Online (Sandbox Code Playgroud)

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

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}
Run Code Online (Sandbox Code Playgroud)

但是很短的时间之后,你可以看到网站加载得很好.

为什么要调用fail方法?而且无论网站是否真的失败,我如何知道它何时实际失败?

Mar*_*era 38

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

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

喜欢

if ([error code] != NSURLErrorCancelled) { //show error alert, etc. }
Run Code Online (Sandbox Code Playgroud)

但我不知道如何识别它被调用的地方.