Question

I'm using an NSSavePanel in my app. Everything works fine on my OS X 10.7, but the application was rejected by Apple, with the following comment:

When exporting for the second time, the previously selected save location does not work. The user has to unselect the location and then select it again in order to have the file written. Please ensure that you have the necessary entitlements.

This review was conducted on an iMac running OS X 10.8.

This is my save panel code:

NSSavePanel *savePanel = [NSSavePanel savePanel];
[savePanel setAllowedFileTypes:[NSArray arrayWithObject:@"mov"]];
[savePanel setDirectoryURL:[NSURL URLWithString:@"/Documents"]];
[savePanel setNameFieldStringValue: videoName];

[savePanel beginSheetModalForWindow:window completionHandler:^(NSInteger result){
    if (result == NSFileHandlingPanelOKButton) {
        NSError *error = nil;
        NSString *sourceFilePath = [NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath], videoName];
        NSString *destFilePath = [[savePanel URL] path];
        NSFileManager *fileManager = [[NSFileManager alloc] init];
        if(![fileManager copyItemAtPath:sourceFilePath toPath:destFilePath error:&error])
            NSLog(@"%@", error);
    }
}];

Currently I'm using these flags:

 <dict>
    <key>com.apple.security.app-sandbox</key>
    <true/>
    <key>com.apple.security.assets.movies.read-write</key>
    <true/>
    <key>com.apple.security.files.downloads.read-write</key>
    <true/>
    <key>com.apple.security.files.user-selected.read-write</key>
    <true/>
</dict>

What entitlement flag do I have to use to solve this issue?

Was it helpful?

Solution

If you're talking about saving twice in the same run of your app, there shouldn't be any entitlement required; once the user selects a file from an NSSavePanel, it's in your app's sandbox. The same applies if the save panel is shown both times – it should "just work". If it's the same location between consecutive runs, without a save panel the second time, you need to store a security-scoped bookmark to the file.

For an example, see the sample code given in this question (and the correction to it in the accepted answer): App Sandbox: document-scoped bookmark not resolving; not returning any error

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top