使用Webview查看iphone中的.doc,.docx,.rtf,.ppt文件 [英] view .doc, .docx, .rtf, .ppt file in iphone using Webview

查看:100
本文介绍了使用Webview查看iphone中的.doc,.docx,.rtf,.ppt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iphone中查看.doc,.docx,.rtf,.ppt文件。

I want to view .doc, .docx, .rtf, .ppt file in iphone.

但我想我的身边出现了问题,而不是为上述格式工作,但我的代码适用于.txt和.pdf文件。

But I guess something is going wrong at my side and its not working for the above formats but my code is working fine for .txt and .pdf files.

我已阅读有关Webview的文档,它声明它支持查看以上内容文件。

I have the read the document regarding Webview it states it supports viewing of the above document.

下面是我的代码片段.doc

below is my snippet for .doc

[webView loadData:requestData MIMEType:@"application/msword" textEncodingName:@"UTF-8" baseURL:nil];

for .ppt我使用MIME类型为application / vnd.ms -powerpoint

for .ppt I am using MIME type as "application/vnd.ms-powerpoint"

注意:如果我为.doc / .rtf制作MIME类型为text / html,那么它会显示一些垃圾数据所以我认为MIME类型中缺少一些东西。

Note: If I am making MIME type as "text/html" for .doc/.rtf then it displays some garbage data So I think there is something missing in MIME type from my side.

非常感谢任何帮助。

等待你的回复。

更新:........

Update:........

NSData似乎存在打开这些类型的文件格式的问题。
我的数据是加密的,所以我不能直接使用
requestWithURL ,其他的事情是我需要传递凭据才能获取文件,如果我使用凭据保存凭据,凭据就无法正常工作

It seems there is some issue with NSData for opening these type of file formats. My data is encrypted so I cannot use requestWithURL directly and other thing is I need to pass credentials to get the file and the credentials doesnt work proplerly if I save the credentials using

[[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:credential
                                        forProtectionSpace:protectionSpace];

然后使用以下内容发出请求

and then make the request using below

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]] ]

我有什么方法可以将NSData用于上述格式,这样我就可以进行异步调用并传递我的凭据,然后解密数据并在WebView中显示它。

Is there any way I can use NSData for the above formats so that I can make async call and pass my credentials and then decrypt the data and show it in WebView.

推荐答案

并非所有格式(docx)都受支持。这看起来像官方消息。在示例中,Apple未指定mime类型。

Not all of those formats (docx) are supported. This looks like the official word. In the example Apple does not specify a mime type.

这个问题表明你必须使用NSURLRequest而不是loadData。

This question suggests that you must use an NSURLRequest instead of loadData.

编辑:

据我所知,您无法直接将数据传递给loadData以获取这些类型。

As far as I have seen, you cannot directly pass data to loadData for these types.

简单的解决方法是写入临时文件。您可以在webViewDidFinishLoad中删除它,或者在文件打开后立即将其删除。

The easy work around is to write to a temporary file. You can delete it in webViewDidFinishLoad or, technically, as soon as the the file has been opened.

努力工作就是使用NSURLCache。您应该能够实现自定义NSURLCache并让WebKit通过setSharedURLCache使用它。您的缓存基本上知道如何获取本地加密文件并假装它们被缓存。我没试过,但我认为这是你最好的选择。这种方法可能会像loadData一样被阻止。

The hard work around is to use NSURLCache. You should be able to implement a custom NSURLCache and have WebKit use it via setSharedURLCache. Your cache would basically know how to get your local encrypted files and pretend that they are cached. I have not tried this, but I think it is your best bet. This approach may be blocked just like loadData is.

这篇关于使用Webview查看iphone中的.doc,.docx,.rtf,.ppt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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