code to open .docx in iphone webView

不羁的心 提交于 2019-12-01 11:28:07

问题


I'm new in iPhone, I'm trying to open .docx file in UIwebView, I wrote the following code

NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"Arabic literature" 
                                                              ofType:@"docx"]; 
NSURL *url  = [NSURL fileURLWithPath:urlAddress];
NSURLRequest *requestObj  = [NSURLRequest requestWithURL:url];

NSData *data = [NSData dataWithContentsOfFile:urlAddress];

//[_webView loadRequest:requestObj];
[_webView loadData:data MIMEType:@"application/vnd.ms-word" textEncodingName:@"UTF-8" baseURL:nil];

but it gives me the following exception:

DiskImageCache: Could not resolve the absolute path of the old directory.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'

consider that I copied the file "Arabic literature.docx" in Supporting files. how can I solve this exception??


回答1:


ok why don't you use something like this:

 NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];

sorry comments were not working,so had to give it as answer.



来源:https://stackoverflow.com/questions/11699850/code-to-open-docx-in-iphone-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!