I'm writing an OS X sandboxed application. It recieves @3x and @2x image files and transforms them into lower resolution images. I'm getting the image URLs by either the files being dragged into the app window or a directory being chosen using NSOpenPanel.
Once the images are dragged or the folder is selected, I run a for loop and resize each image using this method
-(BOOL)writeImage:(NSImage*)image toFile:(NSString*)file withRepresentation:(NSString*)extension{
CGImageRef cgRef = [image CGImageForProposedRect:NULL
context:nil
hints:nil];
NSBitmapImageRep *newRep = [[NSBitmapImageRep alloc] initWithCGImage:cgRef];
[newRep setSize:[image size]];
NSData *pngData = [newRep representationUsingType:[self getRepresentationType:extension] properties:nil];
return [pngData writeToFile:[file stringByAppendingString:[NSString stringWithFormat:@".%@",extension]] atomically:YES];
This breaks the sandbox model. I've read I should be using NSSavePanel, but this would require me to specify the final filepath/filename for each of the saved images, which ruins the user experience.
Is there any way to ask the sandboxed app permision to write to certain directory instead of asking permission to write each file?