检测并自定义 UIWebView 的“无法读取文档”问题错误
我正在使用多种不同的文档类型(.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果检查日志没有显示任何异常,请在实际设备上运行它。作为一点帮助,我的日志显示
这意味着模拟器失败了。在对同样的问题感到沮丧之后,我完成了整个最终认证、安装和配置过程,并确认包含文本的 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
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.