Loading Local PDF File Into WebView(将本地 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将本地 PDF 文件加载到 WebView


基础教程推荐
- Android文本颜色不会改变颜色 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01