将本地 PDF 文件加载到 WebView

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)