Question

I have an application that needs to save a file in the same location as the source file drag on the window of the application. The sandbox does not let me even right after you have checked "User selected File" ....

Thanks.

Was it helpful?

Solution

When dropping a file to your App, sandbox grants only access to this file. You can't even rename it. To write a new file in the same directory, use an NSOpenPanel to get write access to the directory.

eg:

 - (void)showGrantAccessForFolderOfFile:(NSURL *)urlOfFile
 {
    NSURL *urlToGrant = [urlOfFile URLByDeletingLastPathComponent];
    NSOpenPanel *openPanel = [NSOpenPanel openPanel];
    [openPanel setAllowsMultipleSelection:NO];
    [openPanel setCanChooseDirectories:YES];
    [openPanel setCanChooseFiles:NO];
    [openPanel setCanCreateDirectories:NO];
    [openPanel setDirectoryURL:urlToGrant];

    [openPanel setTitle:@"Grant Access To Folder"];
    [openPanel setMessage:@"Please grant access to the file’s folder"];
    [openPanel setPrompt:@"Grant Access"];

    // then run the panel as in documentation and handle errors
    // could also set a delegate and grey out other directories
    // store the sandboxed to access it later again
}

OTHER TIPS

Have you checked Apple's docs, in particular the Drag and Drop Programming Topics ?

Important: Although you can support dragging file paths, in general, you should avoid doing so unless you are certain that the destination app will never be run in an app sandbox. If you use an NSString, OS X has no way to know whether that string should be interpreted as a path; thus, OS X does not expand the destination app’s sandbox to allow access to the file or directory at that location.

Instead, use an NSURL, a bookmark, or a filename pasteboard type.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top