我正在尝试使用UIWebView连接到wikiTravel页面。这是我的代码:
NSURL *url = [NSURL URLWithString:@"http://wikitravel.org/en/Beijing"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[wikiWebView loadRequest:requestObj];
如果我将北京改为康沃尔,它会很有效,并向我展示所有信息。如果我将北京改为蒙特利尔,它只加载wikitravel徽标和两个按钮,但它会调用webViewDidFinishLoad
。但是在北京,它只是加载和加载而不会显示任何内容。
每当调用UIWebView方法时,我都会打印到控制台,这里是输出:
2012-06-11 15:11:50.904 ExtraFeatures3[893:307] WEB VIEW DID START LOAD.
2012-06-11 15:11:57.607 ExtraFeatures3[893:307] WEB VIEW FAILED TO LOAD: Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0x19be10 {NSErrorFailingURLKey=http://wikitravel.org/en/Beijing, NSErrorFailingURLStringKey=http://wikitravel.org/en/Beijing}
2012-06-11 15:11:57.619 ExtraFeatures3[893:307] WEB VIEW DID START LOAD.
2012-06-11 15:11:59.523 ExtraFeatures3[893:307] WEB VIEW FAILED TO LOAD: Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0x1a3190 {NSErrorFailingURLKey=http://wikitravel.org/en/Beijing, NSErrorFailingURLStringKey=http://wikitravel.org/en/Beijing}
2012-06-11 15:11:59.534 ExtraFeatures3[893:307] WEB VIEW DID START LOAD.
2012-06-11 15:12:00.875 ExtraFeatures3[893:307] WEB VIEW FAILED TO LOAD: Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0x1a6e00 {NSErrorFailingURLKey=http://wikitravel.org/en/Beijing, NSErrorFailingURLStringKey=http://wikitravel.org/en/Beijing}
它只是继续前进和前进......我不知道该怎么做。
编辑:我的所有搜索都引导我进行以下解决方法,我已经尝试过并且没有开始工作:
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
if([error code] == NSURLErrorCancelled)
{
return;
}
}
非常感谢任何帮助!
谢谢!
答案 0 :(得分:3)
根据此网站:https://discussions.apple.com/thread/1727260?start=0&tstart=0
这是解决方法:
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"Error %i", error.code);
if (error.code == NSURLErrorCancelled) return; // this is Error -999
// error handling for "real" errors here
}
答案 1 :(得分:1)
而不是尝试您的网址,首先尝试
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
你能加载吗?