0
votes

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?

1
I get the same results for apple provided example MassiveImage developer.apple.com/library/mac/#samplecode/MassiveImage/…) if enable app sandboxing and entitlements. The only entitlement I use is com.apple.security.files.user-selected.read-write. Also I know that somehow overwriting existing file is possible in sandboxed app (standard app 'Preview' is sandboxed and overwrites existing images just fine).Alexander B

1 Answers

3
votes

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.