openURL file not found

Discussion in 'Mac Programming' started by abcdefg12345, May 7, 2015.

  1. abcdefg12345 macrumors regular

    abcdefg12345

    Joined:
    Jul 10, 2013
    #1
    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
     
  2. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #2
    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.
     
  3. abcdefg12345 thread starter macrumors regular

    abcdefg12345

    Joined:
    Jul 10, 2013
    #3
    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];
     
  4. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #4
    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.
     

Share This Page