Iphone 即使稍后加载页面,也会使用UIWebView调用didFailLoadWithError
我有一个UIViewController,它是一个UIWebViewDelegate,里面有一个UIWebView。我正在尝试加载一个特定的URLIphone 即使稍后加载页面,也会使用UIWebView调用didFailLoadWithError,iphone,xcode,ipad,uiwebview,Iphone,Xcode,Ipad,Uiwebview,我有一个UIViewController,它是一个UIWebViewDelegate,里面有一个UIWebView。我正在尝试加载一个特定的URL NSURL *url = [NSURL URLWithString:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [webView loadRequest:requestObj]; [self.view addSub
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self.view addSubview:webView];
[webView release];
但是几乎会立即调用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}
然而,不久之后,你可以看到,网站负载刚刚好
为什么要调用fail方法?我怎么知道它什么时候真正失败了,而不管网站是否真的失败了,方法是什么时候被调用的呢?因此,根据另一个说法,你得到的错误代码是由在前一个请求完成之前发出的请求引起的
可能发生的情况是,您同时/非常快速地进行多个调用,其中一个调用成功(因此您的网页加载),但另一个调用失败。当页面通过javascript或其他方式立即重定向时,您可能会遇到此错误 您可以通过以下方式避免显示错误: 像
但我不知道如何识别调用它的位置。在web视图上使用tapcount为1的Tap手势。 使用一个处理Tap手势的函数,检查URL是否返回状态码200,如果返回,请调用下面的函数
-(void)animateme{
NSString *urlAddress = Connecting_URL
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.webview loadRequest:requestObj];
}
并且,使用委托函数
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Device in offline" message:@"Please check your internet connection" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[alert show];
}
希望有帮助:)`if([error code]!=nsurerrorcancelled){//show error alert,etc.}URL应该都是大写:)我得到了相同的错误,因为第一次使用URL,第二次加载url1。也许这对任何人都有帮助,但这并不能回答问题
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Device in offline" message:@"Please check your internet connection" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[alert show];
}