The following function is called after the savepanel save, the application is basically to splice an image into multiple pictures - this works however when sandboxed it doesn't, I believe it's the save thread which isn't working - does anyone know why this isn't working when sandboxed
- (void)saveThread{
NSLog(@"Save thread started");
@autoreleasepool {
NSImage *image = [[NSImage alloc] initWithContentsOfFile:tileCutterView.filename];
[rowBar setIndeterminate:NO];
[columnBar setIndeterminate:NO];
[rowBar setMaxValue:(double)[image rowsWithTileHeight:[heightTextField floatValue]]];
[rowBar setMinValue:0.];
[rowBar setDoubleValue:0.];
[columnBar setMinValue:0.];
[columnBar setMaxValue:(double)[image columnsWithTileWidth:[widthTextField floatValue]]];
[columnBar setDoubleValue:0.];
progressCol = 0;
progressRow = 0;
tileRowCount = [image rowsWithTileHeight:tileHeight];
tileColCount = [image columnsWithTileWidth:tileWidth];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
TileCutterOutputPrefs outputFormat = (TileCutterOutputPrefs)[defaults integerForKey:@"OutputFormat"];
for (int row = 0; row < tileRowCount; row++)
{
// Each row operation gets its own ImageRep to avoid contention
NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:[image CGImageForProposedRect:NULL context:NULL hints:nil]];
TileOperation *op = [[TileOperation alloc] init];
op.row = row;
op.tileWidth = tileWidth;
op.tileHeight = tileHeight;
op.imageRep = imageRep;
op.baseFilename = baseFilename;
op.delegate = self;
op.outputFormat = outputFormat;
[queue addOperation:op];
}
}
}
UPDATE: I've added the other functions relating to this code:
- (IBAction)saveButtonPressed:(id)sender{
NSSavePanel *sp = [NSSavePanel savePanel];
[sp setRequiredFileType:@"jpg"];
[sp beginSheetForDirectory:[NSString stringWithFormat:@"%@/Pictures", NSHomeDirectory()]
file:@"output.jpg"
modalForWindow:window
modalDelegate:self
didEndSelector:@selector(didEndSaveSheet:returnCode:conextInfo:)
contextInfo:nil];
}
-(void)didEndSaveSheet:(NSSavePanel *)savePanel
returnCode:(int)returnCode conextInfo:(void *)contextInfo
{
if (returnCode == NSOKButton)
{
NSURL *fileURL = [savePanel URL];
NSString *filePath = [fileURL path];
self.baseFilename = filePath;
tileHeight = [heightTextField intValue];
tileWidth = [widthTextField intValue];
[self performSelector:@selector(delayPresentSheet) withObject:nil afterDelay:0.1];
}
}
- (void)delayPresentSheet{
[progressLabel setStringValue:@"Splicing image…"];
[rowBar setIndeterminate:YES];
[columnBar setIndeterminate:YES];
[rowBar startAnimation:self];
[columnBar startAnimation:self];
[NSApp beginSheet: progressWindow
modalForWindow: window
modalDelegate: self
didEndSelector: @selector(didEndSheet:returnCode:contextInfo:)
contextInfo: nil];
[self performSelectorInBackground:@selector(saveThread) withObject:nil];
}
UPDATE: CONSOLE ERROR:
06/05/2015 11:30:49.592 sandboxd[8455]: ([8720]) MyApp(8720) deny file-write-create /Users/Me/Documents/output_1_0.jpg
06/05/2015 11:30:49.592 sandboxd[8455]: ([8720]) MyApp(8720) deny file-write-create /Users/Me/Documents/output_1_1.jpg
06/05/2015 11:30:49.592 sandboxd[8455]: ([8720]) MyApp(8720) deny file-write-create /Users/Me/Documents/output_0_1.jpg