iPhone UIWebView: loadData does not work with certain types (Excel, MSWord, PPT, RTF)(iPhone UIWebView:loadData 不适用于某些类型(Excel、MSWord、PPT、RTF))
问题描述
我的任务是在装有 OS 3.x 的 iPhone 上显示支持的文档类型,例如 .pdf、.rtf、.doc、.ppt、.png、.tiff 等.
My task is to display the supported document types on an iPhone with OS 3.x, such as .pdf, .rtf, .doc, .ppt, .png, .tiff etc.
现在,我已将这些文件仅加密存储在磁盘上.出于安全原因,我想避免将它们未加密地存储在磁盘上.
Now, I have stored these files only encrypted on disk. For security reasons, I want to avoid storing them unencrypted on disk.
因此,我更喜欢使用 loadData:MIMEType:textEncodingName:baseURL:
而不是 loadRequest:
来显示文档,因为 loadData
允许我在 NSData 对象中传递内容,即我可以在内存中解密文件,而无需将其存储在磁盘上,因为使用 loadRequest
时需要它.
Hence, I prefer to use loadData:MIMEType:textEncodingName:baseURL:
instead of loadRequest:
to display the document because loadData
allows me to pass the content in a NSData object, i.e. I can decrypt the file in memory and have no need to store it on disk, as it would be required when using loadRequest
.
问题在于 loadData
似乎不适用于所有文件类型:
The problem is that loadData
does not appear to work with all file types:
测试表明,所有图片类型似乎都可以正常工作,PDF 也是如此,而更复杂的类型则不然.我收到如下错误:
Testing shows that all picture types seem to work fine, as well as PDFs, while the more complex types don't. I get a errors such as:
NSURLErrorDomain Code=100
NSURLErrorDomain Code=102
WebView 似乎需要一个真正有效的 URL 才能将文档作为文件访问,尽管我已经通过 NSData 对象提供了所有内容.
WebView appears to need a truly working URL for accessing the documents as a file, despite me offering all content via the NSData object already.
这是我用来显示内容的代码:
Here's the code I use to display the content:
[webView loadData:data MIMEType:type textEncodingName:@"utf-8" baseURL:nil];
mime-type 设置正确,例如.doc 文件的应用程序/msword".
The mime-type is properly set, e.g. to "application/msword" for .doc files.
有谁知道我如何让 loadData
与 loadRequest 支持的所有类型一起工作?或者,或者,有什么方法可以告诉我哪些类型确实可以使用 loadData肯定(即 Apple 正式批准)?然后我可以双重工作,只为那些 loadData 不喜欢的情况创建一个临时未加密文件.
Does anyone know how I could get loadData
to work with all types that loadRequest supports? Or, alternatively, is there some way I can tell which types do work for sure (i.e. officially sanctioned by Apple) with loadData? Then I can work twofold, creating a temp unencrypted file only for those cases that loadData won't like.
更新
看起来我不是第一个遇到这种情况的人.见这里:
Looks like I'm not the first one running into this. See here:
http://osdir.com/ml/iPhoneSDKDevelopment/2010-03/msg00216.html
所以,我想,这就是现状,我对此无能为力.
So, I guess, that's the status quo, and nothing I can do about it.
有人提出了一种可能可行的解决方法:
Someone suggested a work-around which might work, though:
http://osdir.com/ml/iPhoneSDKDevelopment/2010-03/msg00219.html
基本上,这个想法是提供一个小型 http 服务器来服务文件(在我的例子中是从内存中),然后使用 loadRequest.但是,这可能会占用更多内存,因为服务器和 webview 可能都将整个内容作为两个副本保存在内存中,而不是使用 loadData,两者都宁愿共享相同的数据对象.(请注意,我必须将解密的数据保存在内存中,这就是重点).
Basically, the idea is to provide a tiny http server that serves the file (from memory in my case), and then use loadRequest. This is probably a bit more memory-intensive, though, as both the server and the webview will probably both hold the entire contents in memory as two copies then, as opposed to using loadData, where both would rather share the same data object. (Mind you, I'll have to hold the decrypted data in memory, that's the whole point here).
推荐答案
我遇到了一个非常相似的问题(但是我从服务器获取我的文件)并看到你的帖子并认为这是一个死胡同然后偶然开始在设备(在本例中为 iPad)上进行实验,当我将 baseURL 作为我用来从服务器获取它的内容时它工作,它工作但在模拟器上不起作用.我会尝试这样做,否则我会向 Apple 提交错误报告.
I experienced a very similar issue (i get my files from a server however) and saw your post and thought it was a dead end and then just by chance started to experiment on the device (iPad, in this instance) and it worked when i gave the baseURL as what i used to get it from the server and it worked but does not work on the simulator. I would try that, otherwise I would submit a bug report to Apple.
这篇关于iPhone UIWebView:loadData 不适用于某些类型(Excel、MSWord、PPT、RTF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iPhone UIWebView:loadData 不适用于某些类型(Excel、MSWord、PPT、RTF)
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01