xcode – DiskImageCache:无法解析旧目录的绝对路径.找不到PDF标题:找不到`%PDF’

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

我的头文件代码:

#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

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

- (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];

该应用程序启动正常,不崩溃或任何东西.引用出口已设置,但不显示PDF.控制台说:

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

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

我能在这做什么?任何帮助,将不胜感激.

解决方法

如果您的目标是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];

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...