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.
我真的需要让UIWebView打开我项目目录中的特定PDF文档。我似乎无法找到任何关于此的教程。我发现了一个,但作者并没有具体说明一些代码。
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?
有人可以帮我编写UIWebView来加载PDF吗?
Thanks.
1 个解决方案
#1
13
Use pathForResource and fileURLWithPath:
使用pathForResource和fileURLWithPath:
NSString *path = [[NSBundle mainBundle] pathForResource:@"FileNameHere"
ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
#1
13
Use pathForResource and fileURLWithPath:
使用pathForResource和fileURLWithPath:
NSString *path = [[NSBundle mainBundle] pathForResource:@"FileNameHere"
ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];