检测并自定义 UIWebView 的“无法读取文档”问题错误

发布于 2024-10-04 02:36:48 字数 563 浏览 5 评论 0原文

我正在使用多种不同的文档类型(.xlsx、.jpg 等)测试 UIWebview,并且它可以很好地打开其中的大多数文档。有时,我打开一个本地文件,并且此消息出现在 Web 视图中:

Unable to Read Document
An error occurred while reading the document

我不关心“为什么”会发生此错误 - 例如,当我向 UIWebView 提供垃圾文件时(故意),它会发生。问题是我不知道如何检测“何时”发生这种情况。它不会触发 webView:didFailLoadWithError,也不会触发 NSException (通过 @try@catch strong>),当我检查 webViewDidFinishLoad 中的文档时,webView.request.HTTPBody 为 null。

有人知道如何检测 UIWebView 无法显示内容的情况吗?

I'm testing a UIWebview with a number of different document types - .xlsx, .jpg, etc. - and it opens most of them just fine. From time to time, I open a local file and this message appears right in the web view:

Unable to Read Document
An error occurred while reading the document

I'm not concerned with "why" this error occurs - it happens, for instance, when I feed the UIWebView a garbage file (intentionally). The problem is that I can't figure out how to detect "when" this happens. It doesn't trigger webView:didFailLoadWithError, it doesn't trigger an NSException (via @try & @catch), and when I inspect the document in webViewDidFinishLoad, webView.request.HTTPBody is null.

Anyone know how to detect when UIWebView can't display content?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自此以后,行同陌路 2024-10-11 02:36:48
just call uiwebview delegate method 

- (void)webViewDidStartLoad:(UIWebView *)webView
{

}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *html = [webView stringByEvaluatingJavaScriptFromString:
                      @"document.body.innerHTML"];
    if ([html rangeOfString:@"Unable to Read Document."].location == NSNotFound) {

       NSLog(@"NO Error");

    }
    else
    {
//        NSLog(@"File contains Error");
    }

}
just call uiwebview delegate method 

- (void)webViewDidStartLoad:(UIWebView *)webView
{

}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *html = [webView stringByEvaluatingJavaScriptFromString:
                      @"document.body.innerHTML"];
    if ([html rangeOfString:@"Unable to Read Document."].location == NSNotFound) {

       NSLog(@"NO Error");

    }
    else
    {
//        NSLog(@"File contains Error");
    }

}
攒眉千度 2024-10-11 02:36:48

如果检查日志没有显示任何异常,请在实际设备上运行它。作为一点帮助,我的日志显示

Cannot find data converter callback for uti public.data
Failed to generate preview

这意味着模拟器失败了。在对同样的问题感到沮丧之后,我完成了整个最终认证、安装和配置过程,并确认包含文本的 Word 97 和 Pages / Pages.zip 文件确实在实际设备上显示得很好。解决了。模拟器本身坏了,这非常……令人不安,这个小注释似乎没有进入发行说明,而且也使开发变得有点复杂。然而,解决方法是在 Xcode 中选择设备并部署出来,它应该可以工作。

If inspecting the log does not show anything out of the ordinary, run it on the actual device. As a bit of help, my log says

Cannot find data converter callback for uti public.data
Failed to generate preview

which means that the simulator is failing. After being frustrated with this same problem, I went thru the whole final certification and installation and provisioning process, and too confirm that Word 97 and Pages / Pages.zip files containing text do indeed display just fine on the actual device. SOLVED. The simulator itself is broken, which is very...troubling, that this little note didn't seem to make it into the release notes, and also complicates development a tad bit. However, the work around is to select the Device in Xcode and deploy out, and it should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文