Sandboxed OSX时保存线程不能正常工作NSSavePanel

时间:2015-05-05 21:15:17

标签: objective-c macos sandbox appstore-sandbox nssavepanel

在savepanel保存之后调用以下函数,该应用程序基本上是将图像拼接成多个图片 - 但是当沙箱它不起作用时,我相信它是不起作用的保存线程 - 有没有人知道为什么这个沙箱不起作用

- (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];
    }

}
}

更新:我添加了与此代码相关的其他功能:

- (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];
}

更新:控制台错误:

06/05/2015 11:30:49.592 sandboxd [8455] :( [8720])MyApp(8720)拒绝文件写入创建/Users/Me/Documents/output_1_0.jpg

06/05/2015 11:30:49.592 sandboxd [8455] :( [8720])MyApp(8720)拒绝文件写入创建/Users/Me/Documents/output_1_1.jpg

06/05/2015 11:30:49.592 sandboxd [8455] :( [8720])MyApp(8720)拒绝文件写入创建/Users/Me/Documents/output_0_1.jpg

1 个答案:

答案 0 :(得分:0)

NSSavePanel无法一次授予您访问多个文件的权限。您需要使用NSOpenPanel并要求用户授予整个目录的访问权限。然后使用NSOpenPanel中的NSURL并将您的文件添加到此。

other questionApple Documentation here的答案中提供了更多解释。