Phonegap/Cordova ios加载远程url出错时如何回退到local index.html?

Phonegap/Cordova ios加载远程url出错时如何回退到local index.html?,ios,cordova,Ios,Cordova,我对cordova中的内容使用远程url,我使用appcache使其脱机工作-现在的问题是在appcache初始化之前处理初始加载 在安卓系统中,我让设备返回到local index.html——这可能会提供信息,例如,让用户知道他们必须在线才能完成安装 // On error show default message page... public void onReceivedError( int errorCode, String description, String failin

我对cordova中的内容使用远程url,我使用appcache使其脱机工作-现在的问题是在appcache初始化之前处理初始加载

在安卓系统中,我让设备返回到local index.html——这可能会提供信息,例如,让用户知道他们必须在线才能完成安装

    // On error show default message page...
public void onReceivedError( int errorCode, String description, String failingUrl)
{
    super.loadUrl("file:///android_asset/www/index.html");
    return;
}
问题:“我如何在IOS中实现同样的功能?”

不必为我编写代码-对文件和api的提示将不胜感激

您可以为您提供检测远程内容加载失败的方法。例如:

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
   // here you can either check for the error type or for the url that has failed to load
   if([webView.request.url.absoluteString isEqualToString:@"your_remote_url")]
   {
      NSURL *url = [NSURL urlWithString:@"your_local_url"];
      NSURLRequest *request = [NSURLRequest requestWithURL:url];
      [webview loadRequest:request];
   }
}

由于您只是想做一些错误处理,解决方法之一是创建一个子视图,并从您需要的URL加载它

您可以在此处找到有关如何执行此操作的指南:

当然,这是从本机部分调用的:)


希望有帮助

你不能只使用自定义警报div或javascript吗?@kangoroo我直接从远程url加载-因此没有js来捕捉错误-我明确要求使用本机iOS,因为我不想要js middlewareit只有在你使用cordova时才合理如果你问我,你已经在为此运行引擎了。只是说说而已。实际上,当你撤回cordova上的本机时,你正在消耗更多的资源。上面的android代码在droidGap/webview中-但是cordova没有内置选项,无法在使用远程url时后退。我不认为原生的一行代码会比js代码消耗更多的资源。谢谢@elio.d我认为这是正确的答案,只是一些额外的链接: