Post marked as unsolved
Click to stop watching this post.
You have stopped watching this post. Click to start watching again.
Post marked as unsolved with 3 replies
68
Views
Sandbox allows or denies user-selected files to be saved
Two classes in my sandboxed application need to export a NSDictionary as a plist file.
On the Capabilities, the Permission/Access setting is read/Write for User selected files. I use XCode 10.11.1 on Mojave, and build for ≥10.12. From several classes that need to export files, two are very similar and manage NSDictionary.
For those two, when the user prompts for save, I open a NSSavePanel to choose the destination filename and directory. I use exactly the same code for my two classes:
NSSavePanel *panel = [NSSavePanel savePanel];
[panel setNameFieldStringValue:newFilename];
panel.extensionHidden = TRUE;
[panel beginWithCompletionHandler:^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton) {
NSURL *saveURL = [panel URL];
NSString *savePath = [saveURL path];
if (![[savePath pathExtension] isEqual:@"plist"]){
savePath = [savePath stringByDeletingPathExtension];
savePath = [savePath stringByAppendingString:@".plist"];
}
[exportDic writeToFile:savePath atomically:YES];
}
}];
What is strange is that saving this ways always works for one class that use this code, whereas it doesn't succeed for the second class, except one non-reproductible time! I got no message on the debugger console, but I can see one in the Console application:
Sandbox: MyApp (xxxx) deny(1) file-write-create my_file_path.plist
I verified everything, reset the sandbox setting, clean build folder, quit/relaunched Xcode, and even rebooted the computer several times. Any idea? Thanks