gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:45:28 26 4
gpt4 key购买 nike

我可以在 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 异常?

最佳答案

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

关于ios - 在 UIWebview 中打开一些 xlsx 文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10346662/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com