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

abcdefg12345

macrumors 6502
Original poster
Jul 10, 2013
281
86
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
 

superscape

macrumors 6502a
Feb 12, 2008
937
223
East Riding of Yorkshire, UK
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.
 

abcdefg12345

macrumors 6502
Original poster
Jul 10, 2013
281
86
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];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.