3

我可以在 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]];

但是对于某些文件,我在控制台日志中遇到异常。我不知道这些异常来自哪里以及如何捕获它

<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>

当我尝试在某些加载文件的 webview 中加载第二个文件时,我得到didFailLoadWithError为以前的 xlsx 调用,下面是控制台日志

-----====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 异常?

4

1 回答 1

0

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

于 2012-09-02T14:59:45.807 回答