Good Morning!
I save images in my app using ImageKit IKSaveOptions to present a save panel accessory view that deals with different image settings.
If in the save panel the user select an already existing file, appears the alert box "“XXX” already exists. Do you want to replace it?".
If the user press the "Replace" button, the old file should be replaced (overwritten) by the new one
It works fine when the app is not sandboxed.
however, I started to use the Lion's Sandbox with the "Read/Write Access" entitlement. The old file can not be replaced correctly. The old file is kept and a new file is created. and the new file name is something like 'XXX.jpg.sb-g5Evhc'. I think it a kind of sandbox format file. It is not what I want. I just want to replace the old image file with the new one.
I tried it again: the old image file can be correctly replaced if the app is not sandboxed, but it can not be replaced if the app is sandboxed.
Please help! Any help will be appriciated.
I used the sample code of 'IKImageViewDemo' which can be found on webpage
http://developer.apple.com/library/.../DTS10004049-Controller_m-DontLinkElementID_4
and the code is like below:
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
Jacky
I save images in my app using ImageKit IKSaveOptions to present a save panel accessory view that deals with different image settings.
If in the save panel the user select an already existing file, appears the alert box "“XXX” already exists. Do you want to replace it?".
If the user press the "Replace" button, the old file should be replaced (overwritten) by the new one
It works fine when the app is not sandboxed.
however, I started to use the Lion's Sandbox with the "Read/Write Access" entitlement. The old file can not be replaced correctly. The old file is kept and a new file is created. and the new file name is something like 'XXX.jpg.sb-g5Evhc'. I think it a kind of sandbox format file. It is not what I want. I just want to replace the old image file with the new one.
I tried it again: the old image file can be correctly replaced if the app is not sandboxed, but it can not be replaced if the app is sandboxed.
Please help! Any help will be appriciated.
I used the sample code of 'IKImageViewDemo' which can be found on webpage
http://developer.apple.com/library/.../DTS10004049-Controller_m-DontLinkElementID_4
and the code is like below:
///////////////////////////////////////////////////////////////////////////////////////////////
Code:
- (void)savePanelDidEnd: (NSSavePanel *)sheet
returnCode: (int)returnCode
contextInfo: (void *)contextInfo
{
// save the image
if (returnCode == NSOKButton)
{
NSString * path = [sheet filename];
NSString * newUTType = [_saveOptions imageUTType];
CGImageRef image;
// get the current image from the image view
image = [_imageView image];
if (image)
{
// use ImageIO to save the image in the user specified format
NSURL * url = [NSURL fileURLWithPath: path];
CGImageDestinationRef dest = CGImageDestinationCreateWithURL((CFURLRef)url, (CFStringRef)newUTType, 1, NULL);
if (dest)
{
CGImageDestinationAddImage(dest, image, (CFDictionaryRef)[_saveOptions imageProperties]);
CGImageDestinationFinalize(dest);
CFRelease(dest);
}
} else
{
NSLog(@"*** saveImageToPath - no image");
}
}
}
// ---------------------------------------------------------------------------------------------------------------------
- (IBAction)saveImage: (id)sender
{
// present a save panel - use IKSaveOptions to append the ImageKit accessory view to the save panel
NSSavePanel * savePanel = [NSSavePanel savePanel];
_saveOptions = [[IKSaveOptions alloc] initWithImageProperties: _imageProperties
imageUTType: _imageUTType];
[_saveOptions addSaveOptionsAccessoryViewToSavePanel: savePanel];
NSString * fileName = [[_window representedFilename] lastPathComponent];
[savePanel beginSheetForDirectory: NULL
file: fileName
modalForWindow: _window
modalDelegate: self
didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
contextInfo: NULL];
///////////////////////////////////////////////////////////////////////////////////////////////
Jacky
Last edited by a moderator: