将本地PDF文件加载到WebView中 [英] Loading Local PDF File Into WebView

查看:84
本文介绍了将本地PDF文件加载到WebView中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将以下功能放入我正在编写的iOS应用中:

I am attempting to put the following functionality into an iOS app I am writing:


  • 在资源文件夹中发送一组PDF XCode中的项目

  • 将PDF复制到应用程序目录

  • 在Webview中打开PDF。

据我所知,前两步工作正常(我在复制操作后使用FileManager检查fileExistsAtPath)。
但是,webview为空,并且错误输出(请求的URL在服务器上不存在)。
我打开文件的代码如下:

As far as I can see, the first two steps work ok (I've used FileManager to check fileExistsAtPath after the copy operation). However, the webview is empty, and is erroring out ("the requested URL does not exist on server"). My code for the file open is as follows:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                          NSUserDomainMask, YES);
NSString *localDocumentsDirectory = [paths objectAtIndex:0];
NSString *pdfFileName = @"example.pdf";
NSString *localDocumentsDirectoryPdfFilePath = [localDocumentsDirectory  
                                     stringByAppendingPathComponent:pdfFileName];
pdfUrl = [NSURL fileURLWithPath:localDocumentsDirectoryPdfFilePath];
[webView loadRequest:[NSURLRequestWithURL:pdfUrl];

这在模拟器上工作正常,但在设备上不起作用

This works fine on the simulator, but doesn't work on the device

推荐答案

由Anna Karenina上面发布,设备区分大小写。请确保文件名完全匹配

As posted by Anna Karenina above, "The device is case-sensitive. Make sure the filename matches exactly"

这篇关于将本地PDF文件加载到WebView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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