我创建了一个iPhone
phone gap
应用,它在webView中打开url
,有时没有互联网连接或请求返回404 page not found
或url
已损坏,应用程序返回空白页...
之前我已经在android
发布了一个版本,我以这种方式解决了这个问题:
<!-- Inside config.xml of android app -->
<!-- in this case while 404 it well redirect automatically to error.html -->
<preference name="errorURL" value="file:///android_asset/www/error.html" />
IOS中的类似解决方案是什么?这种情况的最佳方法是什么......
答案 0 :(得分:1)
我对可能的问题进行了艰苦的研究我找到了答案,我想分享一下你很好地找到了这个链接中的解决方案How can I load a local HTML file instead of a web page in Xcode webview?
我用这些步骤解决了我的问题:
error.html
文件夹中创建了www
。MainViewController.m
中的:我找到didFailLoadWithError
方法并从中删除评论并在下面编写此代码:
(void) webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error
{
[theWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html" inDirectory:@"www"] isDirectory:NO]]];
}
答案 1 :(得分:0)
<preference name="errorURL" value="error.html" />
:我创建了didFailLoadWithError方法(参见下面的示例:
-(void) webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error
{
[theWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html" inDirectory:@"www"] isDirectory:NO]]];
}
感谢 @Abu taha ,因为我借用了他的一点想法