xcode 如何让 UIWebView 从它自己的应用程序中显示一个 pdf 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2890246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:22:56  来源:igfitidea点击:

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

iphonexcodepdfipaduiwebview

提问by Aakburns

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.

谢谢。

回答by

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];