Using Cocoa Nssavepanel in Sandbox Causes Assertion Failure

Saving a NSImage to disk on a sandbox app in cocoa - CRASH

[NSSavePanel savePanel];

and

[NSSavePanel openPanel];

simply don't work on OSX 10.10, 10.10.1 and 10.10.2 on storyboard apps.

The solution given by Apple to me was "use Xibs".

After having a long list of problems with storyboard apps on OSX, I don't use them anymore. "Use XIBS" is what I am doing.

Customizing sandboxed NSSavePanel alert

So, after a bit of further digging I can tell the solution of the riddle finally although I can only guess the reasons why it was made tricky by Apple. Apparently NSError exclusively needs to be used. The customization has to be done in userInfo, say

let userInfo = [NSLocalizedDescriptionKey: "yourLocalizedDescription", NSLocalizedRecoverySuggestionErrorKey: "yourSuggestion"]
throw NSError(domain: "whatever", code: 0, userInfo: userInfo)

etc. By the way subclassing NSError doesn't work, the Sandbox will just happily ignore you :)

App doesn't close after using NSSavePanel

Try this:

   NSSavePanel*    panel = [NSSavePanel savePanel];
[panel setNameFieldStringValue:newName];
[panel beginSheetModalForWindow:[self window] completionHandler:^(NSInteger result){
if (result == NSFileHandlingPanelOKButton)
{
NSURL* theFile = [panel URL];
// Write the contents in the new format.
}
}];

I faced the same issue and this solved it.
For window you can alternatively use [NSApp keyWindow]

Apple guideline with sandboxing.



Related Topics



Leave a reply



Submit