Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

iphone - didFailLoadWithError is called with UIWebView even though page later loads

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];

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.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

like

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...