IKSaveOptions saving images error when app is sandboxed

Discussion in 'Mac Programming' started by jacky7728, Aug 10, 2011.

  1. jacky7728, Aug 10, 2011
    Last edited by a moderator: Aug 11, 2011

    jacky7728 macrumors newbie

    Jun 15, 2011
    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
    and the code is like below:

    - (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]);
            } 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];

  2. jacky7728 thread starter macrumors newbie

    Jun 15, 2011
  3. Alexander B. macrumors member

    Alexander B.

    Aug 2, 2011
    Hi Jacky!

    Did you have any success on solving the issue with saving image in sandboxed app?

Share This Page