Reputation: 697
I am attempting to load a local pdf file using the following code for a Cocoa project (not an iOS project).
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"testPDFFile"
ofType:@"pdf"
inDirectory:@""];
NSURL* fileURL = [NSURL fileURLWithPath:filePath];
NSURLRequest* request = [NSURLRequest requestWithURL:fileURL];
[[webView mainFrame] loadRequest:request];
I can see the WebView object is loading, but the document is not shown. It looks like the Outlet is connected correctly.
I have tried moving the file to various directory locations, and have tried specifying a directory in the inDirectory parameter.
Currently, the file is located in the “Supporting Files” directory. If I change inDirectory to read… inDirectory:@”Supporting Files”]; I receive an error that says… “[NSURL initFileURLWithPath:]: nil string parameter”
How can I get this statement to find and show my file?
Upvotes: 0
Views: 283
Reputation: 1059
Try:
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"testPDFFile"
ofType:@"pdf"];
As long, as you are accessing resources in your own bundle, you don't have to set a (foreign) bundle directory.
Upvotes: 1