【发布时间】:2012-04-27 07:39:57
【问题描述】:
我可以在 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 异常?
【问题讨论】:
-
我遇到了同样的问题,我认为这与 xls 格式的类型有关(在我的情况下,是基于 xml 的 xls)...您找到任何解决方法了吗?
-
我在打开受密码保护的 .xlsx/.docx 时遇到了这个问题