问题描述
我已经检查了文档支持的官方链接,并且明确指出UIWebview不支持docx,
I have checked the official links for doc support, and its clear that docx is not supported in UIWebview,
但是,我也发现有些人能够在UIWebview中打开docx文件,
But , i also found out that some guys were able to open docx files in UIWebview,
,
另外,还有iOS移动浏览器在UIWebview上,我可以在浏览器中从互联网上打开docx文件。
但是当我从我的测试服务器下载docx时(我已经通过从模拟器导入它来交叉检查下载的docx并且它在我的mac上完全打开),我无法在UIWebview中查看它。
Also, afaik, iOS safari browser is built upon UIWebview and i am able to open docx files from internet in the browser.But when I download a docx from my test server(I have cross checked the downloaded docx by importing it from simulator and it opens perfectly on my mac), i am unable to view it in UIWebview.
我很困惑,
docx是否支持?
或者看来docx还有更多种格式支持吗?
I am confused,Is docx Supported or not? Or it seems that docx has further variety of formats out which some are supported?
这是我的加载代码,
NSURLRequest *request = [NSURLRequest requestWithURL:urlPath];
[webViewForDocsView loadRequest:request];
推荐答案
不知道为什么但是使用URL方案来负载的docx没有工作,(下面的代码没有工作)
Don't know why but using the URL scheme to load docx didn't worked,(below code didn't worked)
NSURLRequest *request = [NSURLRequest requestWithURL:urlPath];
[webViewForDocsView loadRequest:request];
而是将文件加载到内存中(使用NSData)并加载MIME类型的数据(下面)代码就像魅力一样!)
Instead loading the file in memory(using NSData) and loading the data with MIME type worked(the below code worked like charm!)
NSString *path = [urlFileInView path];
NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];
webViewForDocsView.delegate = self;
[webViewForDocsView loadData:data MIMEType:@"application/vnd.openxmlformats-officedocument.wordprocessingml.document" textEncodingName:@"UTF-8" baseURL:nil];
这篇关于UIWebview(iOS)中的Docx支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!