iPhone UIWebView:loadData不适用于某些类型(Excel,MSWord,PPT,RTF) [英] iPhone UIWebView: loadData does not work with certain types (Excel, MSWord, PPT, RTF)

查看:103
本文介绍了iPhone UIWebView:loadData不适用于某些类型(Excel,MSWord,PPT,RTF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是在带有OS 3.x的iPhone上显示支持的文档类型,例如.pdf,.rtf,.doc,.ppt,.png,.tiff等。



现在,我已将这些文件 仅加密 存储在磁盘上。出于安全原因,我想避免将它们以未加密的方式存储在磁盘上。



因此,我更喜欢使用 loadData:MIMEType:textEncodingName:baseURL:而不是 loadRequest:显示文档,因为 loadData 允许我传递内容NSData对象,即我可以在内存中解密文件而不需要将其存储在磁盘上,因为在使用 loadRequest 时需要它。



问题是 loadData 似乎不适用于所有文件类型:



测试显示所有图片类型似乎都可以正常工作,而PDF则更好,而更复杂的类型则不然。我收到如下错误:

  NSURLErrorDomain Code = 100 
NSURLErrorDomain Code = 102

尽管我已经通过NSData对象提供了所有内容,但WebView似乎需要一个真正有效的URL来作为文件访问文档。 / p>

这是我用来显示内容的代码:

  [webView loadData:data MIMEType:type textEncodingName:@utf-8baseURL:nil]; 

mime-type已正确设置,例如:到.doc文件的application / msword。



有谁知道如何使用 loadData 来处理loadRequest支持的所有类型?或者,或者,有什么方法可以告诉哪些类型确实 (即Apple正式批准)使用loadData?然后我可以双重工作,只为loadData不喜欢的情况创建一个临时未加密的文件。



更新



看起来我不是第一个碰到这个的人。请参阅此处:



http ://osdir.com/ml/iPhoneSDKDevelopment/2010-03/msg00216.html



所以,我猜,那是现状,没什么我的可以做些什么。



有人提出了一个可行的解决办法,但是:



http://osdir.com/ml/iPhoneSDKDevelopment/2010-03/msg00219.html



基本上,我们的想法是提供一个服务于文件的小型http服务器(在我的情况下来自内存),然后使用loadRequest。这可能是内存密集型的,因为服务器和webview可能都将内存中的全部内容保存为两个副本,而不是使用loadData,两者都希望共享相同的数据对象。 (请注意,我必须将解密数据保存在内存中,这就是重点。)

解决方案

我经历过一个非常相似的问题(我从服务器获取我的文件)然后看到你的帖子并认为这是一个死胡同然后只是偶然开始在设备上进行实验(在这个例子中是iPad)当它给了我baseURL就像我以前从服务器上获取它并且它工作但在模拟器上不起作用。我会尝试,否则我会向Apple提交错误报告。


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.

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.

The problem is that loadData does not appear to work with all file types:

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 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];

The mime-type is properly set, e.g. to "application/msword" for .doc files.

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.

Update

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

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).

解决方案

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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆