1

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

user1887683
  • 133
  • 2
  • 7
  • Did you turn on User Selected Files in capabilities? – qwerty_so May 05 '15 at 21:25
  • I have indeed, i've added the relating functions so you have a better understanding on what is going on. – user1887683 May 05 '15 at 21:59
  • the code shows that you only work with filename. where do you ask user for permission to write several? files into a directory? use the NSURL of the save panel which includes the security scope. Furthermore you'll find error messages from sandbox not in Xcode but in Console. What does it log? – mahal tertin May 06 '15 at 09:35
  • Ok on didEndSaveSheet I change the filename code with URL instead, the code had been updated on the top, i've also attached the console error at the top. How can i get it to approve several files into a directory when sandboxed? – user1887683 May 06 '15 at 10:45

1 Answers1

0

NSSavePanel can not grant you access for several files at once. You need to use a NSOpenPanel and ask the user to grant access for the whole directory. Use then the NSURL from the NSOpenPanel and add your files to this.

More explanation in the answer of your other question and in the Apple Documentation here.

Community
  • 1
  • 1
mahal tertin
  • 3,239
  • 24
  • 41