在UIWebview中打开一些xlsx文件时出错

时间:2012-04-27 07:39:58

标签: ios exception uiwebview

我可以在UIWebview

中成功打开xlsx文件的本地副本
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@",[detailItem valueForKey:@"path"]]];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
[self.documentWebview loadRequest:[NSURLRequest requestWithURL:fileURL]];

但是对于某些文件我在控制台日志中得到了Exception。我不知道这些异常来自哪里&如何捕获那个

<Warning>: exception: Could not find the end of central directory record
<Warning>: EXCEPTION SFUZipEndOfCentralDirectoryError: Could not find the end of central directory record

此文件仅开始加载

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType <br>
- (void)webViewDidStartLoad:(UIWebView *)webView

被召唤 &安培;下面的代表都没有被称为

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
- (void)webViewDidFinishLoad:(UIWebView *)aWebView <br>

当我尝试在某个加载文件&amp;的webview中加载第二个文件时我为之前的xlsx调用了 didFailLoadWithError 以下是控制台日志

-----====UIWebview shouldStartLoadWithRequest: /var/mobile/Applications/08653237-F656-42F7-B405-1F89C208A866/Documents/12 So1 what is new in Excel 2007.xlsx =======-------
webViewDidStartLoad 
exception: Could not find the end of central directory record 
EXCEPTION SFUZipEndOfCentralDirectoryError: Could not find the end of central directory record

记录第二个文件

webView didFailLoadWithError: Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0x5655c30 {NSErrorFailingURLKey=file:///var/mobile/Applications/08653237-F656-42F7-B405-1F89C208A866/Documents/12%20So1%20what%20is%20new%20in%20Excel%202007.xlsx, NSErrorFailingURLStringKey=file:///var/mobile/Applications/08653237-F656-42F7-B405-1F89C208A866/Documents/12%20So1%20what%20is%20new%20in%20Excel%202007.xlsx}
webViewDidStartLoad

Detail View finished /var/mobile/Applications/08653237-F656-42F7-B405-1F89C208A866/Documents/a.txt :


这是由于UIWebview缓存吗?如何捕获UIWebview异常?

1 个答案:

答案 0 :(得分:0)

可能是因为您的文件元数据已损坏。我遇到了同样的问题,但发现url响应实际上是一个html页面错误,它是从IIS服务器返回的数据。我把它直接写到文件中。不过,我在&amp; error变量中没有收到任何错误。这实际上是一个服务器错误!