IOS中PhoneGap的错误处理页面

时间:2014-01-13 13:01:27

标签: ios cordova

我创建了一个iPhone phone gap应用,它在webView中打开url,有时没有互联网连接或请求返回404 page not foundurl已损坏,应用程序返回空白页...

之前我已经在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中的类似解决方案是什么?这种情况的最佳方法是什么......

2 个答案:

答案 0 :(得分:1)

我对可能的问题进行了艰苦的研究我找到了答案,我想分享一下你很好地找到了这个链接中的解决方案How can I load a local HTML file instead of a web page in Xcode webview?

我用这些步骤解决了我的问题:

  1. 我在error.html文件夹中创建了www
  2. MainViewController.m中的
  3. :我找到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)

  1. 我在Xcode中的staging文件夹下的www文件夹中创建了error.html。
  2. 我在Xcode中的staging文件夹下的config.xml中进行了更改,如下所示
  3. <preference name="errorURL" value="error.html" />

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

    感谢 @Abu taha ,因为我借用了他的一点想法