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
Convert Int to Uint32 in Swift
An Nsmanagedobject of Class 'Classname' Must Have a Valid Nsentitydescription.' Error
Why Does an Optional in Fast Enumeration Cause an Infinite Loop
How to Add a Bottom Line on Textfield (Swiftui)
Why Does My Pfanalytics Not Have Trackappopenewithlaunchoptions Function? (iOS Swift)
Swift: Assigning Function to Variable
How to Capture Local Variable Inside an Async Closure in Swift
How to Cancel Dispatchqueue.Main.Asyncafter(Deadline: Time) in Swift3
Swift - Initialize View Controller from Storyboard by Overriding Init
Xcode 8 Swift Update with Error "Use Legacy Swift Language Version"
Xcode 9 - Test Target X Encountered an Error (Unable to Connect to Test Manager)
How to Remove All Nodes from a Scenekit Scene
How to Navigate to a New View from Navigationbar Button Click in Swiftui