How do I make UIWebView show a pdf file from its own app?

旧巷老猫 提交于 2019-12-19 06:34:06

问题


I really need to make a UIWebView open up a specific PDF document that is in my project directory. I can't seem to find any tutorials on this. I found one, but the author was not specific about some of the code.

I have to assume it's got to be quite a simple bit of code.

Can someone help me code UIWebView to load a PDF?

Thanks.


回答1:


Use pathForResource and fileURLWithPath:

NSString *path = [[NSBundle mainBundle] pathForResource:@"FileNameHere" 
                                                 ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];


来源:https://stackoverflow.com/questions/2890246/how-do-i-make-uiwebview-show-a-pdf-file-from-its-own-app

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