Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c NSSavePanel在沙盒中时不工作?-OSX&x2022;目标C_Objective C_Macos_Sandbox_Appstore Sandbox_Nssavepanel - Fatal编程技术网

Objective c NSSavePanel在沙盒中时不工作?-OSX&x2022;目标C

Objective c NSSavePanel在沙盒中时不工作?-OSX&x2022;目标C,objective-c,macos,sandbox,appstore-sandbox,nssavepanel,Objective C,Macos,Sandbox,Appstore Sandbox,Nssavepanel,我的应用程序中有以下保存面板。我最近试着用沙盒保存,但不幸的是,沙盒保存似乎不起作用 我知道beginSheetForDirectory被贬值了,所以可能这就是它不起作用的原因?我怎样才能让它与沙箱一起工作 - (IBAction)saveButtonPressed:(id)sender { NSSavePanel *sp = [NSSavePanel savePanel]; [sp setRequiredFileType:@"jpg"]; [sp beginSheet

我的应用程序中有以下保存面板。我最近试着用沙盒保存,但不幸的是,沙盒保存似乎不起作用

我知道beginSheetForDirectory被贬值了,所以可能这就是它不起作用的原因?我怎样才能让它与沙箱一起工作

- (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) 
    {
     self.baseFilename = [[savePanel filename] stringByDeletingPathExtension];
     tileHeight = [heightTextField intValue];
     tileWidth = [widthTextField intValue];

     [self performSelector:@selector(delayPresentSheet) withObject:nil afterDelay:0.1];
    }
} 

当您处于沙盒状态时,您不能只访问任何文件。你的应用程序需要访问该文件的权限。因此,任何为您提供路径的API都不可能工作。沙盒无法确定文件名是否来自保存面板

有新的API返回URL,这些URL以某种方式拥有访问内置文件的权限。您需要使用该URL;如果你想在以后(退出并重新启动应用程序后)使用它,你必须将URL与任务一起存储

这只是它的工作原理,你需要查阅苹果的文档来了解细节。问题不在于旧的API已被弃用,而是它没有为您提供包含沙箱权限的特殊URL