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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With