开发者

NSSavePanel, CGImageDestinationFinalize and OS X sandbox

开发者 https://www.devze.com 2023-04-06 10:43 出处:网络
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 f

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开发者_如何学JAVA, 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消