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

问题描述

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

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

  • 在 XCode 中项目的资源文件夹中发送一组 PDF
  • 将 PDF 复制到应用目录
  • 在网络视图中打开 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 00:27