NSSavePanel,CGImageDestinationFinalize和OS X沙箱

时间:2011-09-22 08:18:04

标签: core-graphics osx-lion sandbox nssavepanel

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

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

选择新文件以保存图像时有效,但是当我选择现有文件时,它会创建除现有文件之外的奇怪命名文件,并且无法覆盖目标URL的内容。更糟糕的是,我没有得到任何错误的回报,也无法检测到失败。这是CoreGraphics或我的代码中的错误吗?这个问题有解决方法吗?

1 个答案:

答案 0 :(得分:3)

最后,我发现核心图形调用的组合覆盖在沙盒环境中工作的现有图像:CGDataConsumerCreateWithURL后跟CGImageDestinationCreateWithDataConsumer。因此,似乎CGImageDestinationCreateWithURL在启用沙盒时被破坏(至少在OS X Lion 10.7.1中)。