2

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?

Community
  • 1
  • 1
Dennis Liger
  • 1,488
  • 2
  • 13
  • 28

1 Answers1

1

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

Community
  • 1
  • 1
Dov
  • 15,530
  • 13
  • 76
  • 177
  • Are you able to save the same file twice when you run in Lion? If so, is it possible for you to run on Mountain Lion, since that's how it's being tested? Maybe the file is locked before the second write, due to an API change. If it works the first time, I doubt it has anything to do with entitlements, despite what the app review team may have suggested. And if you can't reproduce it, then maybe the app review team's comments aren't leading us to the correct conclusion. – Dov Sep 23 '12 at 12:56
  • I've seen a number of situations where the review team give misleading information for the reason they reject. – Mark Sep 23 '12 at 20:19