Re: Canceling NSSavePanel Hang App

Sak Wathanasin

On 2 Apr 2020, at 18:54, Sandor Szatmari <> wrote:

Took a guess and enabled sandbox and added read/write to user selected file and the hang went away.  Is it true that I cannot make an unsandboxed app and uses the NSSavePanel?  I know this is a data point of one, so I want to be careful what conclusions I draw… any thoughts?

No, I have a non-sandboxed app and it works fine. I think the problem is that you are using NSSavePanel:runModal. If you look in the doc'n, it says:

"This method invokes NSApplication's runModalForWindow ..."

If it's doing that, then you need to cancel the modal yourslef (as with any call of runModalForWindow). Try putting a

[NSApp stopModalWithCode:NSModalResponseCancel];

in your "else" clause.

However, it may be simpler to use a sheet modal:
...setup code...
    [panel beginSheetModalForWindow:owningWindow
                  completionHandler:^(NSInteger result){
                      if (result == NSFileHandlingPanelOKButton)
                          self.saveFileURL = [[panel URLs] objectAtIndex:0];
                          [self writeToFileAtURL:self.saveFileURL];

You can spin the writing to a file off to a separate thread if it takes a long time.

Hope this helps,


Join to automatically receive all group messages.