简体   繁体   English

iOS无法将PDF显示在UIWebView中

[英]iOS Can't Get PDF to Appear in UIWebView

I'm having issues displaying a PDF in a UIWebView - something that should be really trivial (even for me beginner level). 我在UIWebView中显示PDF时遇到了问题-这应该是微不足道的(即使是我的初学者水平)。 However I'm not seeing anything. 但是我什么也没看见。

I have a UIWebView correctly connected as an IBOutlet, then in the viewDidLoad, i have the following code: 我有一个UIWebView正确连接为IBOutlet,然后在viewDidLoad中,我有以下代码:

NSURL *targetURL = [NSURL URLWithString:@"/Users/tom........../PDF_6.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[_pdfWebView loadRequest:request];

Any ideas what I'm doing wrong?? 任何想法我在做什么错?

Thanks. 谢谢。

(Apologies if this is a really duplicated question i just can't find the answer). (如果这是一个重复的问题,我很抱歉,我只是找不到答案)。

Since it seems you want to load the PDF from a file, you need to create a file URL: 由于似乎要从文件加载PDF,因此需要创建文件URL:

NSURL *targetURL = [NSURL fileURLWithPath:@"/Users/tom........../PDF_6.pdf"];

BTW - that path is only going to work in the simulator, not on a real iOS device. 顺便说一句-该路径仅在模拟器中有效,而不能在真实的iOS设备上起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM