2

I'm trying to set the directory url in an NSSavePanel so that it opens the panel to that directory but it doesn't work when the I set it to a path in my app's document folder.

NSSavePanel *panel = [NSSavePanel savePanel];
NSString *fileFolder = @"/Users/me/Library/Containers/com.company.app/Data/Documents/MyFolder";
NSURL *folderURL = [NSURL URLWithString:folder];
[panel setDirectoryURL:folderURL];

If I programmatically open the path using Finder it works so I don't understand why the path wouldn't work through NSSavePanel.

[[NSWorkspace sharedWorkspace] @"/Users/me/Library/Containers/com.company.app/Data/Documents/MyFolder" withApplication:@"Finder"];
Berry Blue
  • 15,330
  • 18
  • 62
  • 113
  • Just on the off chance that you haven't tried them, I've got a couple of suggestions: (i) add the scheme to the ``fileFolder`` string so it becomes: *@"file:///Users/me...*, create the ``folderURL`` with this string, then run ``[[NSFileManager defaultManager] fileExistsAtPath:[folderURL path]]``, and check that the returned boolean indicates that your url is valid. Also, can you include in your question the call you use to actually bring the save panel on to the screen. – Paul Patterson Nov 12 '14 at 09:23
  • 1
    Is your project **sandboxed**? – cacau Nov 12 '14 at 09:29
  • Yes, the project is sandboxed. I tried adding the file scheme but it made no difference. -fileExistsAtPath: for that folder returns YES. – Berry Blue Nov 12 '14 at 17:34
  • 1
    I have the same problem on 10.10.5. The sandbox won't allow this behavior for some reason but it works fine if the app is not sandboxed. – GenericPtr Sep 22 '15 at 03:49

0 Answers0