xcode DiskImageCache:无法解析旧目录的绝对路径。未能找到 PDF 标题:未找到“%PDF”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25412424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:25:07  来源:igfitidea点击:

DiskImageCache: Could not resolve the absolute path of the old directory. failed to find PDF header: `%PDF' not found

xcodepdf

提问by Stephan K?nig

In one of my views, I simply want to show a pdf file in a UIWebView.

在我的一个视图中,我只想在 UIWebView 中显示一个 pdf 文件。

My code of the header file:

我的头文件代码:

    #import <UIKit/UIKit.h>

@interface FCOMViewController : UIViewController

{IBOutlet UIWebView *fcomWebView;}

//flag to denote if this is first time the app is run

@property (nonatomic) BOOL firstRun;

@end

And here the method in the implementation file:

这里是实现文件中的方法:

- (void)viewDidLoad {

    //Show the procedures PDF

NSString *path = [[NSBundle mainBundle] pathForResource:@"b777normalprocedures" ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[fcomWebView loadRequest:request];
[fcomWebView setScalesPageToFit:YES];

The app starts fine, does not crash or anything. The referencing outlets are set, but it doesn't show the PDF. Console says:

该应用程序启动良好,没有崩溃或任何事情。参考出口已设置,但不显示 PDF。控制台说:

DiskImageCache: Could not resolve the absolute path of the old directory. failed to find PDF header: `%PDF' not found.

DiskImageCache:无法解析旧目录的绝对路径。未能找到 PDF 标题:未找到“%PDF”。

The pdf is in the project directory, I have double checked that it is written correctly.

pdf 在项目目录中,我已经仔细检查过它是否正确写入。

What can I do here? Any help would be appreciated.

我可以在这里做什么?任何帮助,将不胜感激。

回答by Xavier

Try this if you are targeting iOS 8.0:

如果你的目标是 iOS 8.0,试试这个:

 NSString *path = [[NSBundle mainBundle] pathForResource:@"b777normalprocedures" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:targetURL];
[_webView loadData:pdfData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];

回答by Theis Egeberg

For me the problem was with downloaded pdf files which had extensions that I presume was otherwise recognised by UIWebView (aspx,php etc.). When I renamed the downloaded pdf files so that they had a ".pdf" extension the error did not occur.

对我来说,问题在于下载的 pdf 文件具有扩展名,我认为 UIWebView(aspx、php 等)以其他方式识别了这些扩展名。当我重命名下载的 pdf 文件以便它们具有“.pdf”扩展名时,没有发生错误。