2011-09-22 72 views
0

我正在使用NSSavePanel让用户选择图像保存到我的应用程序。一切工作正常,直到我启用应用程序沙箱和权利。选择已存在的文件时会出现问题。我的代码是这样的:NSSavePanel,CGImageDestinationFinalize和OS X沙箱

//创建一个URL到我们的文件目的地和一个CGImageDestination进行保存。 CGImageDestinationRef imageDestination = CGImageDestinationCreateWithURL((CFURLRef)[savePanel URL],(CFStringRef)newUTType,1,NULL); CGImageDestinationAddImage(imageDestination,cgimage,(CFDictionaryRef)metaData); const bool result = CGImageDestinationFinalize(imageDestination);

它选择新文件保存图像,但当我选择现有的文件,它会创建除现有的文件之外的奇怪的命名文件,并无法覆盖目标网址的内容。更糟糕的是,我没有收到任何错误,也无法检测到故障。这是CoreGraphics还是我的代码中的错误?有没有解决这个问题的方法?

+0

如果启用应用程序沙箱和权利,我会得到与Apple提供的示例相同的结果MassiveImage http://developer.apple.com/library/mac/#samplecode/MassiveImage/Introduction/Intro.html)。我使用的唯一权利是com.apple.security.files.user-selected.read-write。此外,我知道,在沙盒应用程序(标准应用程序'预览'是沙盒并覆盖现有的图像就好了)以某种方式覆盖现有的文件是可能的。 –

回答

3

最后,我发现核心图形调用的组合覆盖了沙盒环境中已有的图像:CGDataConsumerCreateWithURL,然后是CGImageDestinationCreateWithDataConsumer。所以看起来CGImageDestinationCreateWithURL已损坏(至少在OS X Lion 10.7.1)并启用了沙箱。