Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

abcdefg12345

macrumors 6502
Original poster
I'm trying to add a pdf file to my app and and open it when a button is clicked however for some reason i keep on getting an error that file cant be found.

thats what I'm using

Code:
[[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:@"appname.app/Contents/Resources/samplepdf.pdf"]];

when i open the contents of the app manually i can find the .pdf file in the resources folder but why cant the app find it
 
Hi,

Not sure about your specific case, but personally I usually use:

Code:
NSString *path = [[NSBundle mainBundle] pathForResource:@"filenamegoeshere" ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];

Try it that way and see if it's any better.
 
Hi,

Not sure about your specific case, but personally I usually use:

Code:
NSString *path = [[NSBundle mainBundle] pathForResource:@"filenamegoeshere" ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];

Try it that way and see if it's any better.

thanks
that codes seems to be working for me

Code:
NSString *path = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"pdf"];
    NSURL *url = [NSURL fileURLWithPath:path];
    [[NSWorkspace sharedWorkspace] openURL:url];
 
Actually, I *do* see where you went wrong - can't believe I missed it. You didn't supply the full path to the app's Resources folder, you started at the location of the app.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.