NSSavePanel无法在沙盒中工作吗? -OSX•目标C [英] NSSavePanel not working when sandboxed? - OSX • Objective C

查看:139
本文介绍了NSSavePanel无法在沙盒中工作吗? -OSX•目标C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中具有以下保存面板.我最近尝试对它进行沙箱测试,但是不幸的是,当沙箱保存似乎无法正常工作时.

I have the following save panel in my app. I have recently tried to sandbox it but unfortunately when sandboxed saving doesn't seem to be working.

我知道beginSheetForDirectory已贬值,所以可能这就是为什么它不起作用的原因?如何使它与沙盒一起使用?

I understand that beginSheetForDirectory is depreciated, so possibly that's why it's not working? How can I get this to work with sandboxing?

- (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都可能有效.沙箱将不可能确定文件名是否来自保存面板.

When you are sandboxed, you cannot just access any file. Your app needs permission to access that file. So any API that gives you a path cannot possibly work. It would be impossible for the sandbox to figure out whether the filename came from a save panel or not.

有一些新的API返回一个URL,这些URL以某种方式具有访问内置于其中的文件的权限.您需要使用该URL.如果您想稍后使用它(退出并重新启动应用程序之后),则必须将URL与任务一起存储.

There are new APIs returning a URL, and these URLs somehow have the permission for accessing a file built into them. You need to use that URL; if you want to use it later (after you quit and restart the app) you have to store the URL together with the mission.

这只是工作原理,您需要查阅Apple文档以获取详细信息.问题不在于旧的API已被弃用,问题在于它没有提供包含沙箱权限的特殊URL.

That's just the principles how it works, you need to consult Apple's documentation for details. The problem isn't that the old API is deprecated, the problem is that it doesn't give you a special URL that includes permissions for the sandbox.

这篇关于NSSavePanel无法在沙盒中工作吗? -OSX•目标C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆