【发布时间】:2011-09-21 15:10:49
【问题描述】:
我正在尝试将以下功能放入我正在编写的 iOS 应用程序中:
- 在 XCode 中项目的资源文件夹中发送一组 PDF
- 将 PDF 复制到应用目录
- 在网络视图中打开 PDF。
据我所知,前两个步骤工作正常(复制操作后我使用 FileManager 检查 fileExistsAtPath)。 但是,webview 是空的,并且出错(“请求的 URL 在服务器上不存在”)。 我的文件打开代码如下:
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];
这在模拟器上可以正常工作,但在设备上不起作用
【问题讨论】:
-
设备区分大小写。确保文件名完全匹配。
-
安娜,谢谢!我正要说我已经检查过了。但是当我回去再次查看时,.pdf 实际上是 .PDF 如果您将此添加为答案,我会将其标记为已解决。再次感谢。