NSSavePanel,CGImageDestinationFinalize和OS X沙箱 [英] NSSavePanel, CGImageDestinationFinalize and OS X sandbox

查看:124
本文介绍了NSSavePanel,CGImageDestinationFinalize和OS X沙箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NSSavePanel让用户选择要保存到我的应用程序中的图像。一切正常,直到我启用了应用程序沙箱和授权。选择一个已经存在的文件会出现问题。我的代码是这样的:

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:

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

// 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);

在选择新文件保存图像时可以使用,但是当我选择现有文件时会创建奇怪的命名文件除了现有文件,而且无法覆盖目标网址的内容。更糟糕的是,我没有得到任何回报,也无法检测到故障。这是CoreGraphics还是我的代码中的错误?

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?

推荐答案

最后,我发现核心图形调用的组合覆盖了已在其中运行的现有图像。沙盒环境: 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 by CGImageDestinationCreateWithDataConsumer. So it seems CGImageDestinationCreateWithURL is broken (at least in OS X Lion 10.7.1) with sandbox enabled.

这篇关于NSSavePanel,CGImageDestinationFinalize和OS X沙箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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