如何让UIWebView从自己的应用程序中显示pdf文件? [英] How do I make UIWebView show a pdf file from its own app?

查看:115
本文介绍了如何让UIWebView从自己的应用程序中显示pdf文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的需要让UIWebView打开我项目目录中的特定PDF文档。我似乎无法找到任何关于此的教程。我发现了一个,但是作者并没有具体说明一些代码。

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.

有人可以帮我编写UIWebView来加载PDF吗?

Can someone help me code UIWebView to load a PDF?

谢谢。

推荐答案

使用pathForResource和fileURLWithPath:

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

这篇关于如何让UIWebView从自己的应用程序中显示pdf文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆