Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSOpenPanel in sandboxed app ignores provided directory URL

I am building sandboxed OS X app (OS X 10.10.5, Xcode 6.4). In the course of execution I open NSOpenPanel object. Then I run next snippet:

NSString* s=[@"~" stringByExpandingTildeInPath]; 
NSOpenPanel* panel = [NSOpenPanel openPanel];
[panel setCanChooseDirectories:YES];
[panel setCanChooseFiles:NO];
NSURL* url=[NSURL fileURLWithPath:s];
if(url){
    [panel setDirectoryURL:url];
}
[panel setAllowsMultipleSelection:YES];
[panel beginSheetModalForWindow:[self.outlineView window]completionHandler:^(NSInteger result) {}

My expectation is that panel opens in directory /Users/xxx/Library/Containers/com.123456.App/

Instead that the panel opens in directory /Users/xxx

Application is actually built and deployed into directory /Users/xxx/Library/Containers/com.123456.App/Data/

While debugging I observe that at this point:

if(url){
    [panel setDirectoryURL:url];
}

url contains correct value: file:///Users/xxx/Library/Containers/com.123456.App/Data/

Any idea?

like image 831
BorisV Avatar asked Sep 03 '15 15:09

BorisV


1 Answers

Is there a reason why you want to use an NSOpenPanel in the app's container? The container is meant for the app's internal data/support files (which users generally should not need to access). NSOpenPanel/NSSavePanel are used for the user to select a file/directory out of their own documents, which would not be located in the container.

Also, consider using NSFileManager URLsForDirectory:inDomains: to get an NSURL to the desired path.

like image 148
Brendan Shanks Avatar answered Nov 13 '22 16:11

Brendan Shanks