Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xcode

pdf

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

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:

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

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

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

like image 267
Stephan König Avatar asked Aug 20 '14 18:08

Stephan König


1 Answers

Try this if you are targeting 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];
like image 156
Xavier Avatar answered Nov 16 '22 16:11

Xavier