NSSavePanel、CGImageDestinationFinalize 和 OS X 沙箱
我正在使用 NSSavePanel 让用户选择要保存到我的应用程序中的图像。一切工作正常,直到我启用应用程序沙箱和权利。选择已存在的文件时会出现此问题。我的代码是这样的:
// 创建一个指向我们的文件目标的 URL 和一个要保存到的 CGImageDestination。 CGImageDestinationRef imageDestination = CGImageDestinationCreateWithURL((CFURLRef)[savePanel URL], (CFStringRef)newUTType, 1, NULL); CGImageDestinationAddImage(imageDestination, cgimage, (CFDictionaryRef)metaData); const bool 结果 = CGImageDestinationFinalize(imageDestination);
它在选择新文件来保存图像时有效,但是当我选择现有文件时,它会在现有文件之外创建奇怪的命名文件,并且无法覆盖目标 url 的内容。更糟糕的是,我没有收到任何错误返回,也无法检测到故障。这是 CoreGraphics 中的错误还是我的代码中的错误?这个问题有什么解决方法吗?
I'm using NSSavePanel to let user select image to save to in my app. Everything worked fine until I enabled app sandboxing and entitlements. The problem occurs with selection of an already existing file. My code is like this:
// Create a URL to our file destination and a CGImageDestination to save to.
CGImageDestinationRef imageDestination = CGImageDestinationCreateWithURL((CFURLRef)[savePanel URL], (CFStringRef)newUTType, 1, NULL);
CGImageDestinationAddImage(imageDestination, cgimage, (CFDictionaryRef)metaData);
const bool result = CGImageDestinationFinalize(imageDestination);
It works when selecting new file to save the image, but when I select existing file it creates strange named file besides existing file and fails to overwrite the contents of destination url. And even worse, I get no error in return and cannot detect the failure. Is this a bug in CoreGraphics or in my code? Is there any workaround for this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,我发现了核心图形调用的组合,可以覆盖在沙盒环境中工作的现有图像:
CGDataConsumerCreateWithURL
,然后是CGImageDestinationCreateWithDataConsumer
。因此,启用沙箱后,CGImageDestinationCreateWithURL
似乎已损坏(至少在OS X Lion 10.7.1
中)。Finally I have discovered combination of core graphics calls to overwrite an already existing image working in sandboxed environment:
CGDataConsumerCreateWithURL
followed byCGImageDestinationCreateWithDataConsumer
. So it seemsCGImageDestinationCreateWithURL
is broken (at least inOS X Lion 10.7.1
) with sandbox enabled.