NSSavePanel, CGImageDestinationFinalize and OS X sandbox
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.
精彩评论